Skip to content

Commit 943c4e3

Browse files
committed
Updated _macro_list to use a method to build its parser.
1 parent a8a4293 commit 943c4e3

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

cmd2/cmd2.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4059,25 +4059,31 @@ def _macro_delete(self, args: argparse.Namespace) -> None:
40594059
self.perror(f"Macro '{cur_name}' does not exist")
40604060

40614061
# macro -> list
4062-
macro_list_help = "list macros"
4063-
macro_list_description = Text.assemble(
4064-
"List specified macros in a reusable form that can be saved to a startup script to preserve macros across sessions.",
4065-
"\n\n",
4066-
"Without arguments, all macros will be listed.",
4067-
)
4062+
@classmethod
4063+
def _build_macro_list_parser(cls) -> Cmd2ArgumentParser:
4064+
macro_list_description = Text.assemble(
4065+
(
4066+
"List specified macros in a reusable form that can be saved to a startup script "
4067+
"to preserve macros across sessions."
4068+
),
4069+
"\n\n",
4070+
"Without arguments, all macros will be listed.",
4071+
)
40684072

4069-
macro_list_parser = argparse_custom.DEFAULT_ARGUMENT_PARSER(description=macro_list_description)
4070-
macro_list_parser.add_argument(
4071-
'names',
4072-
nargs=argparse.ZERO_OR_MORE,
4073-
help='macro(s) to list',
4074-
choices_provider=_get_macro_completion_items,
4075-
descriptive_headers=["Value"],
4076-
)
4073+
macro_list_parser = argparse_custom.DEFAULT_ARGUMENT_PARSER(description=macro_list_description)
4074+
macro_list_parser.add_argument(
4075+
'names',
4076+
nargs=argparse.ZERO_OR_MORE,
4077+
help='macro(s) to list',
4078+
choices_provider=cls._get_macro_completion_items,
4079+
descriptive_headers=["Value"],
4080+
)
4081+
4082+
return macro_list_parser
40774083

4078-
@as_subcommand_to('macro', 'list', macro_list_parser, help=macro_list_help)
4084+
@as_subcommand_to('macro', 'list', _build_macro_list_parser, help="list macros")
40794085
def _macro_list(self, args: argparse.Namespace) -> None:
4080-
"""List some or all macros as 'macro create' commands."""
4086+
"""List macros."""
40814087
self.last_result = {} # dict[macro_name, macro_value]
40824088

40834089
tokens_to_quote = constants.REDIRECTION_TOKENS

0 commit comments

Comments
 (0)