Skip to content
Myr

defaults -> settings

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 c71b7ed · Browse files · 6 files+21 added−21 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+21 added−21 removed

  • tests:+4 added−4 removed
  • other:+17 added−17 removed

6 files+21 added−21 removed

modified:click/core.py+9 added-9 removed
357 unmodified lines
358 operations. For instance, they cannot be used with the decorators359 usually and they have no built-in callback system.360361 .. versionchanged:: 2.0362 Added the `context_defaults` parameter.362 Added the `context_settings` parameter.363364 :param name: the name of the command to use unless a group overrides it.365 :param context_defaults: an optional dictionary with defaults that are365 :param context_settings: an optional dictionary with defaults that are366 passed to the context object.367 """368369 def __init__(self, name, context_defaults=None):369 def __init__(self, name, context_settings=None):370 #: the name the command thinks it has. Upon registering a command371 #: on a :class:`Group` the group will default the command name372 #: with this information. You should instead use the373 #: :class:`Context`\'s :attr:`~Context.info_name` attribute.374 self.name = name375 #: an optional dictionary with defaults passed to the context.376 self.context_defaults = context_defaults376 self.context_settings = context_settings377378 def get_usage(self, ctx):379 raise NotImplementedError('Base commands cannot get usage')380
14 unmodified lines
395 :param parent: the parent context if available.396 :param extra: extra keyword arguments forwarded to the context397 constructor.398 """399 for key, value in iteritems(self.context_defaults or {}):399 for key, value in iteritems(self.context_settings or {}):400 if key not in extra:401 extra[key] = value402 ctx = Context(self, info_name=info_name, parent=parent, **extra)403 self.parse_args(ctx, args)
89 unmodified lines
493 click. A basic command handles command line parsing and might dispatch494 more parsing to commands nested below it.495496 .. versionchanged:: 2.0497 Added the `context_defaults` parameter.497 Added the `context_settings` parameter.498499 :param name: the name of the command to use unless a group overrides it.500 :param context_defaults: an optional dictionary with defaults that are500 :param context_settings: an optional dictionary with defaults that are501 passed to the context object.502 :param callback: the callback to invoke. This is optional.503 :param params: the parameters to register with this command. This can504 be either :class:`Option` or :class:`Argument` objects.
6 unmodified lines
511 option. This can be disabled by this parameter.512 """513 allow_extra_args = False514515 def __init__(self, name, context_defaults=None, callback=None,515 def __init__(self, name, context_settings=None, callback=None,516 params=None, help=None, epilog=None, short_help=None,517 options_metavar='[OPTIONS]', add_help_option=True):518 BaseCommand.__init__(self, name, context_defaults)518 BaseCommand.__init__(self, name, context_settings)519 #: the callback to execute when the command fires. This might be520 #: `None` in which case nothing happens.521 self.callback = callback522 #: the list of parameters for this command in the order they
809 unmodified lines
modified:docs/advanced.rst+2 added-2 removed
77 unmodified lines
78function that converts the token to lowercase. Example:7980.. click:example::8182 CONTEXT_DEFAULTS = dict(token_normalize_func=lambda x: x.lower())82 CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())8384 @click.command(context_defaults=CONTEXT_DEFAULTS)84 @click.command(context_settings=CONTEXT_SETTINGS)85 @click.option('--name', default='Pete')86 def cli(name):87 click.echo('Name: %s' % name)88
103 unmodified lines
modified:docs/commands.rst+2 added-2 removed
317 unmodified lines
318.. click:example::319320 import click321322 CONTEXT_DEFAULTS = dict(322 CONTEXT_SETTINGS = dict(323 default_map={'runserver': {'port': 5000}}324 )325326 @click.group(context_defaults=CONTEXT_DEFAULTS)326 @click.group(context_settings=CONTEXT_SETTINGS)327 def cli():328 pass329330 @cli.command()
12 unmodified lines
modified:docs/documentation.rst+2 added-2 removed
146 unmodified lines
147instad of just ``--help``:148149.. click:example::150151 CONTEXT_DEFAULTS = dict(help_option_names=['-h', '--help'])151 CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])152153 @click.command(context_defaults=CONTEXT_DEFAULTS)153 @click.command(context_settings=CONTEXT_SETTINGS)154 def cli():155 pass156157And what it looks like:
4 unmodified lines
modified:examples/complex/complex/cli.py+2 added-2 removed
1 unmodified line
2import sys3import click456CONTEXT_DEFAULTS = dict(auto_envvar_prefix='COMPLEX')6CONTEXT_SETTINGS = dict(auto_envvar_prefix='COMPLEX')789class Context(object):10
38 unmodified lines
49 return50 return mod.cli515253@click.command(cls=ComplexCLI, context_defaults=CONTEXT_DEFAULTS)53@click.command(cls=ComplexCLI, context_settings=CONTEXT_SETTINGS)54@click.option('--home', type=click.Path(exists=True, file_okay=False,55 resolve_path=True),56 help='Changes the folder to operate on.')57@click.option('-v', '--verbose', is_flag=True,
7 unmodified lines
modified:tests/test_normalization.py+4 added-4 removed
1import click234CONTEXT_DEFAULTS = dict(token_normalize_func=lambda x: x.lower())4CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())567def test_option_normalization(runner):8 @click.command(context_defaults=CONTEXT_DEFAULTS)8 @click.command(context_settings=CONTEXT_SETTINGS)9 @click.option('--foo')10 @click.option('-x')11 def cli(foo, x):12 click.echo(foo)
3 unmodified lines
16 assert result.output == '42\n23\n'171819def test_choice_normalization(runner):20 @click.command(context_defaults=CONTEXT_DEFAULTS)20 @click.command(context_settings=CONTEXT_SETTINGS)21 @click.option('--choice', type=click.Choice(['Foo', 'Bar']))22 def cli(choice):23 click.echo('Foo')24
1 unmodified line
26 assert result.output == 'Foo\n'272829def test_command_normalization(runner):30 @click.group(context_defaults=CONTEXT_DEFAULTS)30 @click.group(context_settings=CONTEXT_SETTINGS)31 def cli():32 pass3334 @cli.command()
5 unmodified lines