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
Provenance
- Commit
1bc0a19- Tree
b67932c- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
c71b7ed
6 files changed+21 added−21 removed
modified:click/core.py+9 added-9 removed
357 unmodified lines358 operations. For instance, they cannot be used with the decorators359 usually and they have no built-in callback system.360 361 .. versionchanged:: 2.0362- Added the `context_defaults` parameter.362+ Added the `context_settings` parameter.363 364 :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 """368 369- 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_settings377 378 def get_usage(self, ctx):379 raise NotImplementedError('Base commands cannot get usage')380 14 unmodified lines395 :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 lines493 click. A basic command handles command line parsing and might dispatch494 more parsing to commands nested below it.495 496 .. versionchanged:: 2.0497- Added the `context_defaults` parameter.497+ Added the `context_settings` parameter.498 499 :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 lines511 option. This can be disabled by this parameter.512 """513 allow_extra_args = False514 515- 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 they809 unmodified linesmodified:docs/advanced.rst+2 added-2 removed
77 unmodified lines78 function that converts the token to lowercase. Example:79 80 .. click:example::81 82- CONTEXT_DEFAULTS = dict(token_normalize_func=lambda x: x.lower())82+ CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())83 84- @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 linesmodified:docs/commands.rst+2 added-2 removed
317 unmodified lines318 .. click:example::319 320 import click321 322- CONTEXT_DEFAULTS = dict(322+ CONTEXT_SETTINGS = dict(323 default_map={'runserver': {'port': 5000}}324 )325 326- @click.group(context_defaults=CONTEXT_DEFAULTS)326+ @click.group(context_settings=CONTEXT_SETTINGS)327 def cli():328 pass329 330 @cli.command()12 unmodified linesmodified:docs/documentation.rst+2 added-2 removed
146 unmodified lines147 instad of just ``--help``:148 149 .. click:example::150 151- CONTEXT_DEFAULTS = dict(help_option_names=['-h', '--help'])151+ CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])152 153- @click.command(context_defaults=CONTEXT_DEFAULTS)153+ @click.command(context_settings=CONTEXT_SETTINGS)154 def cli():155 pass156 157 And what it looks like:4 unmodified linesmodified:examples/complex/complex/cli.py+2 added-2 removed
1 unmodified line2 import sys3 import click4 5 6-CONTEXT_DEFAULTS = dict(auto_envvar_prefix='COMPLEX')6+CONTEXT_SETTINGS = dict(auto_envvar_prefix='COMPLEX')7 8 9 class Context(object):10 38 unmodified lines49 return50 return mod.cli51 52 53-@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 linesmodified:tests/test_normalization.py+4 added-4 removed
1 import click2 3 4-CONTEXT_DEFAULTS = dict(token_normalize_func=lambda x: x.lower())4+CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())5 6 7 def 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 lines16 assert result.output == '42\n23\n'17 18 19 def 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 line26 assert result.output == 'Foo\n'27 28 29 def test_command_normalization(runner):30- @click.group(context_defaults=CONTEXT_DEFAULTS)30+ @click.group(context_settings=CONTEXT_SETTINGS)31 def cli():32 pass33 34 @cli.command()5 unmodified lines