diff options
Diffstat (limited to 'examples/complex')
-rw-r--r-- | examples/complex/complex/cli.py | 29 | ||||
-rw-r--r-- | examples/complex/complex/commands/cmd_init.py | 10 | ||||
-rw-r--r-- | examples/complex/complex/commands/cmd_status.py | 9 | ||||
-rw-r--r-- | examples/complex/setup.py | 14 |
4 files changed, 30 insertions, 32 deletions
diff --git a/examples/complex/complex/cli.py b/examples/complex/complex/cli.py index 0d10c62..c539fe8 100644 --- a/examples/complex/complex/cli.py +++ b/examples/complex/complex/cli.py @@ -1,13 +1,13 @@ import os import sys + import click -CONTEXT_SETTINGS = dict(auto_envvar_prefix='COMPLEX') +CONTEXT_SETTINGS = dict(auto_envvar_prefix="COMPLEX") class Environment(object): - def __init__(self): self.verbose = False self.home = os.getcwd() @@ -25,17 +25,14 @@ class Environment(object): pass_environment = click.make_pass_decorator(Environment, ensure=True) -cmd_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), - 'commands')) +cmd_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "commands")) class ComplexCLI(click.MultiCommand): - def list_commands(self, ctx): rv = [] for filename in os.listdir(cmd_folder): - if filename.endswith('.py') and \ - filename.startswith('cmd_'): + if filename.endswith(".py") and filename.startswith("cmd_"): rv.append(filename[4:-3]) rv.sort() return rv @@ -43,20 +40,22 @@ class ComplexCLI(click.MultiCommand): def get_command(self, ctx, name): try: if sys.version_info[0] == 2: - name = name.encode('ascii', 'replace') - mod = __import__('complex.commands.cmd_' + name, - None, None, ['cli']) + name = name.encode("ascii", "replace") + mod = __import__( + "complex.commands.cmd_{}".format(name), None, None, ["cli"] + ) except ImportError: return return mod.cli @click.command(cls=ComplexCLI, context_settings=CONTEXT_SETTINGS) -@click.option('--home', type=click.Path(exists=True, file_okay=False, - resolve_path=True), - help='Changes the folder to operate on.') -@click.option('-v', '--verbose', is_flag=True, - help='Enables verbose mode.') +@click.option( + "--home", + type=click.Path(exists=True, file_okay=False, resolve_path=True), + help="Changes the folder to operate on.", +) +@click.option("-v", "--verbose", is_flag=True, help="Enables verbose mode.") @pass_environment def cli(ctx, verbose, home): """A complex command line interface.""" diff --git a/examples/complex/complex/commands/cmd_init.py b/examples/complex/complex/commands/cmd_init.py index a77116b..c2cf770 100644 --- a/examples/complex/complex/commands/cmd_init.py +++ b/examples/complex/complex/commands/cmd_init.py @@ -1,13 +1,13 @@ -import click from complex.cli import pass_environment +import click + -@click.command('init', short_help='Initializes a repo.') -@click.argument('path', required=False, type=click.Path(resolve_path=True)) +@click.command("init", short_help="Initializes a repo.") +@click.argument("path", required=False, type=click.Path(resolve_path=True)) @pass_environment def cli(ctx, path): """Initializes a repository.""" if path is None: path = ctx.home - ctx.log('Initialized the repository in %s', - click.format_filename(path)) + ctx.log("Initialized the repository in %s", click.format_filename(path)) diff --git a/examples/complex/complex/commands/cmd_status.py b/examples/complex/complex/commands/cmd_status.py index 12229c4..92275bb 100644 --- a/examples/complex/complex/commands/cmd_status.py +++ b/examples/complex/complex/commands/cmd_status.py @@ -1,10 +1,11 @@ -import click from complex.cli import pass_environment +import click + -@click.command('status', short_help='Shows file changes.') +@click.command("status", short_help="Shows file changes.") @pass_environment def cli(ctx): """Shows file changes in the current working directory.""" - ctx.log('Changed files: none') - ctx.vlog('bla bla bla, debug info') + ctx.log("Changed files: none") + ctx.vlog("bla bla bla, debug info") diff --git a/examples/complex/setup.py b/examples/complex/setup.py index dee002c..afe9728 100644 --- a/examples/complex/setup.py +++ b/examples/complex/setup.py @@ -1,15 +1,13 @@ from setuptools import setup setup( - name='click-example-complex', - version='1.0', - packages=['complex', 'complex.commands'], + name="click-example-complex", + version="1.0", + packages=["complex", "complex.commands"], include_package_data=True, - install_requires=[ - 'click', - ], - entry_points=''' + install_requires=["click"], + entry_points=""" [console_scripts] complex=complex.cli:cli - ''', + """, ) |