Skip to content
Myr

options for handling command name change in 7.0

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

authored by David Lord · committed by David Lord · parent 588440b · Browse files · 1 file+26 added−1 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+26 added−1 removed

  • other:+26 added−1 removed

1 file+26 added−1 removed

modified:docs/upgrading.rst+26 added-1 removed
8 unmodified lines
9.. _upgrade-to-7.0:1011Upgrading to 7.012----------------13Click 7.0 changed the default behaviour of subcommands. Subcommands that are named by the function now automatically have the underscore replaced with a dash. So now, if you register a function named `my_command` it becomes `my-command` in the command line interface by default. Thus, you can still use underscores by specifying the command names explicitly or use a `Command` subclass that doesn't have the new behavior.1314Commands that take their name from the decorated function now replace15underscores with dashes. For example, the Python function ``run_server``16will get the command name ``run-server`` now. There are a few options17to address this:1819- To continue with the new behavior, pin your dependency to20 ``Click>=7`` and update any documentation to use dashes.21- To keep existing behavior, add an explicit command name with22 underscores, like ``@click.command("run_server")``.23- To try a name with dashes if the name with underscores was not24 found, pass a ``token_normalize_func`` to the context:2526 .. code-block:: python2728 def normalize(name):29 return name.replace("_", "-")3031 @click.group(context_settings={"token_normalize_func": normalize})32 def group():33 ...3435 @group.command()36 def run_server():37 ...383940.. _upgrade-to-3.2:4142Upgrading to 3.243----------------
88 unmodified lines