diff --git a/src/click/core.py b/src/click/core.py index 6adc65ccd6..f28ee8adf3 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -985,6 +985,7 @@ def to_info_dict(self, ctx: Context) -> dict[str, t.Any]: "short_help": self.short_help, "hidden": self.hidden, "deprecated": self.deprecated, + "usage": self.get_usage(ctx), } def __repr__(self) -> str: diff --git a/tests/test_info_dict.py b/tests/test_info_dict.py index 20fe68cc13..d8336c9541 100644 --- a/tests/test_info_dict.py +++ b/tests/test_info_dict.py @@ -73,6 +73,7 @@ "short_help": None, "hidden": False, "deprecated": False, + "usage": "Usage: [OPTIONS]", }, ) HELLO_GROUP = ( @@ -85,7 +86,19 @@ "short_help": None, "hidden": False, "deprecated": False, - "commands": {"hello": HELLO_COMMAND[1]}, + "usage": "Usage: [OPTIONS] COMMAND [ARGS]...", + "commands": { + "hello": { + "name": "hello", + "params": [NUMBER_OPTION[1], HELP_OPTION[1]], + "help": None, + "epilog": None, + "short_help": None, + "hidden": False, + "deprecated": False, + "usage": "Usage: hello [OPTIONS]", + }, + }, "chain": False, }, ) @@ -231,8 +244,31 @@ def test_parameter(obj, expect): "short_help": None, "hidden": False, "deprecated": False, + "usage": "Usage: [OPTIONS] COMMAND [ARGS]...", "commands": { - "cli": HELLO_GROUP[1], + "cli": { + "name": "cli", + "params": [HELP_OPTION[1]], + "help": None, + "epilog": None, + "short_help": None, + "hidden": False, + "deprecated": False, + "usage": "Usage: cli [OPTIONS] COMMAND [ARGS]...", + "commands": { + "hello": { + "name": "hello", + "params": [NUMBER_OPTION[1], HELP_OPTION[1]], + "help": None, + "epilog": None, + "short_help": None, + "hidden": False, + "deprecated": False, + "usage": "Usage: cli hello [OPTIONS]", + }, + }, + "chain": False, + }, "test": { "name": "test", "params": [NAME_ARGUMENT[1], HELP_OPTION[1]], @@ -241,6 +277,7 @@ def test_parameter(obj, expect): "short_help": None, "hidden": False, "deprecated": False, + "usage": "Usage: test [OPTIONS] NAME", }, }, "chain": False,