Skip to content
Myr

Underscores are now replaced by dashes in commands

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 7a10fe1 · Browse files · 4 files+25 added−8 removed
This commit

State

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

Diff stats

4 files+25 added−8 removed

  • tests:+20 added−6 removed
  • other:+5 added−2 removed

4 files+25 added−8 removed

modified:click/decorators.py+2 added-2 removed
83 unmodified lines
84 else:85 help = inspect.cleandoc(help)86 attrs['help'] = help87 _check_for_unicode_literals()88 return cls(name=name or f.__name__.lower(),88 return cls(name=name or f.__name__.lower().replace('_', '-'),89 callback=f, params=params, **attrs)909192def command(name=None, cls=None, **attrs):
11 unmodified lines
104 that can be invoked as a command line utility or be attached to a105 command :class:`Group`.106107 :param name: the name of the command. This defaults to the function108 name.108 name with underscores replaced by dashes.109 :param cls: the command class to instantiate. This defaults to110 :class:`Command`.111 """112 if cls is None:
196 unmodified lines
modified:tests/test_commands.py+16 added-2 removed
60 unmodified lines
61 assert re.search(62 r'Commands:\n\s+'63 r'long\s+This is a long text that is too long to show\.\.\.\n\s+'64 r'short\s+This is a short text\.\n\s+'65 r'special_chars\s+Login and store the token in ~/.netrc\.\s*',65 r'special-chars\s+Login and store the token in ~/.netrc\.\s*',66 result.output) is not None676869def test_default_maps(runner):
135 unmodified lines
205 @click.command()206 @click.option('--foo', type=click.INT, default=42)207 @click.pass_context208 def other_cmd(ctx, foo):209 assert ctx.info_name == 'other_cmd'209 assert ctx.info_name == 'other-cmd'210 click.echo(foo)211212 result = runner.invoke(cli, [])213 assert not result.exception
38 unmodified lines
252 assert result.output.splitlines() == [253 'Verbosity: 4',254 'Args: -foo|-x|--muhaha|x|y|-x',255 ]256257258def test_subcommand_naming(runner):259 @click.group()260 def cli():261 pass262263 @cli.command()264 def foo_bar():265 click.echo('foo-bar')266267 result = runner.invoke(cli, ['foo-bar'])268 assert not result.exception269 assert result.output.splitlines() == ['foo-bar']
modified:tests/test_formatting.py+4 added-4 removed
72 unmodified lines
73 """7475 # 54 is chosen as a length where the second line is one character76 # longer than the maximum length.77 result = runner.invoke(cli, ['a_very_long', 'command', '--help'],77 result = runner.invoke(cli, ['a-very-long', 'command', '--help'],78 terminal_width=54)79 assert not result.exception80 assert result.output.splitlines() == [81 'Usage: cli a_very_long command [OPTIONS] FIRST SECOND',81 'Usage: cli a-very-long command [OPTIONS] FIRST SECOND',82 ' THIRD FOURTH FIFTH',83 ' SIXTH',84 '',85 ' A command.',
24 unmodified lines
110 def command():111 """A command.112 """113114 result = runner.invoke(cli, ['a_very_very_very_long', 'command', '--help'],114 result = runner.invoke(cli, ['a-very-very-very-long', 'command', '--help'],115 terminal_width=54)116 assert not result.exception117 assert result.output.splitlines() == [118 'Usage: cli a_very_very_very_long command ',118 'Usage: cli a-very-very-very-long command ',119 ' [OPTIONS] FIRST SECOND THIRD FOURTH FIFTH',120 ' SIXTH',121 '',122 ' A command.',
92 unmodified lines
modified:CHANGES+3 added
29 unmodified lines
30 chained commands when a required option/argument was being completed.31 See #790.32- Allow autocompletion function to determine whether or not to return33 completions that start with the incomplete argument.34- Subcommands that are named by the function now automatically have the35 underscore replaced with a dash. So if you register a function named36 `my_command` it becomes `my-command` in the command line interface.3738Version 6.839-----------40
357 unmodified lines