Updated repo script a bit
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent dad8501 · Browse files · 1 file·+77 added−24 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+77 added−24 removed
- other:+77 added−24 removed
Provenance
- Commit
ca1dff9- Tree
297c1f4- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
dad8501
1 file changed+77 added−24 removed
modified:examples/repo/repo.py+77 added-24 removed
1 import os2+import sys3+import posixpath4+5 import click6 7 8 class Repo(object):9 10 def __init__(self, home):11 self.home = home12+ self.config = {}13+ self.verbose = False14 15+ def set_config(self, key, value):16+ self.config[key] = value17+ if self.verbose:18+ click.echo(' config[%s] = %s' % (key, value), file=sys.stderr)19+20 def __repr__(self):21 return '<Repo %r>' % self.home22 23 24 pass_repo = click.make_pass_decorator(Repo)25 26 27 @click.group()18-@click.option('--repo-home', envvar='REPO_HOME', default='.repo')28+@click.option('--repo-home', envvar='REPO_HOME', default='.repo',29+ metavar='PATH', help='Changes the repository folder location.')30+@click.option('--config', nargs=2, multiple=True,31+ metavar='KEY VALUE', help='Overrides a config key/value pair.')32+@click.option('--verbose', '-v', is_flag=True,33+ help='Enables verbose mode.')34+@click.version_option('1.0')35 @click.pass_context20-def cli(ctx, repo_home):36+def cli(ctx, repo_home, config, verbose):37 """Repo is a command line tool that showcases how to build complex38 command line interfaces with Click.39+40+ This tool is supposed to look like a distributed version control41+ system to show how something like this can be structured.42 """24- # Create a repo object and remember it as as the context object.43+ # Create a repo object and remember it as as the context object. From44+ # this point onwards other commands can refer to it by using the45+ # @pass_repo decorator.46 ctx.obj = Repo(os.path.abspath(repo_home))47+ ctx.obj.verbose = verbose48+ for key, value in config:49+ ctx.obj.set_config(key, value)50 51 52 @cli.command()53 @click.argument('src')54 @click.argument('dest', required=False)55 @click.option('--shallow/--deep', default=False,56 help='Makes a checkout shallow or deep. Deep by default.')33-@click.option('--with-readline/--without-readline', default=False,34- help='Makes a checkout shallow or deep. Deep by default.')57+@click.option('--rev', '-r', default='HEAD',58+ help='Clone a specific revision instead of HEAD.')59 @pass_repo36-def clone(repo, src, dest, shallow):60+def clone(repo, src, dest, shallow, rev):61 """Clones a repository.62 63 This will clone the repository at SRC into the folder DEST. If DEST64 is not provided this will automatically use the last path component65 of SRC and create that folder.66 """43- print('Repo: %s' % repo)44- print('Source: %s' % src)45- print('Destination: %s' % dest)46- print('Shallow: %s' % shallow)67+ if dest is None:68+ dest = posixpath.split(src)[-1] or '.'69+ click.echo('Cloning repo %s to %s' % (src, os.path.abspath(dest)))70+ repo.home = dest71+ if shallow:72+ click.echo('Making shallow checkout')73+ click.echo('Checking out revision %s' % rev)74 75 76 @cli.command()77 @click.confirmation_option()2 unmodified lines80 """Deletes a repository.81 82 This will throw away the current repository.83 """57- print('Repo: %s' % repo)58- print('Deleted')84+ click.echo('Destroying repo %s' % repo.home)85+ click.echo('Deleted!')86 87 88 @cli.command()62-@click.option('--username', prompt=True, required=True)63-@click.option('--email', prompt='E-Mail', required=True)64-@click.password_option()89+@click.option('--username', prompt=True,90+ help='The developer\'s shown username.')91+@click.option('--email', prompt='E-Mail',92+ help='The developer\'s email address')93+@click.password_option(help='The login password.')94 @pass_repo95 def setuser(repo, username, email, password):96 """Sets the user credentials.97 98 This will override the current user config.99 """71- print('Repo: %s' % repo)72- print('Username: %s' % username)73- print('E-Mail: %s' % email)74- print('Password: %s' % ('*' * len(password)))100+ repo.set_config('username', username)101+ repo.set_config('email', email)102+ repo.set_config('password', '*' * len(password))103+ click.echo('Changed credentials.')104 105 106 @cli.command()78-@click.option('--message', '-m', required=True, multiple=True)107+@click.option('--message', '-m', required=True, multiple=True,108+ help='The commit message. If provided multiple times each '109+ 'argument gets converted into a new line.')110+@click.argument('files', nargs=-1)111 @pass_repo80-def commit(repo, message):81- """Commits outstanding changes."""82- print('Repo: %s' % repo)83- print('\n'.join(message))112+def commit(repo, files, message):113+ """Commits outstanding changes.114+115+ Commit changes to the given files into the repository. You will need to116+ "repo push" to push up your changes to other repositories.117+118+ If a list of files is omitted, all changes reported by "repo status"119+ will be committed.120+ """121+ click.echo('Files to be committed: %s' % (files,))122+ click.echo('Commit message:\n' + '\n'.join(message))123+124+125+@cli.command(short_help='Copies files.')126+@click.option('--force', is_flag=True,127+ help='forcibly copy over an existing managed file')128+@click.argument('src', nargs=-1)129+@click.argument('dst')130+@pass_repo131+def copy(repo, src, dst):132+ """Copies one or multiple files to a new location. This copies all133+ files from SRC to DST.134+ """135+ for fn in src:136+ click.echo('Copy from %s -> %s' % (src, dst))