Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated _macro_list to use a method to build its parser.
  • Loading branch information
kmvanbrunt committed Feb 5, 2026
commit 943c4e330c32135d2db578c96174a621cfb0b28f
38 changes: 22 additions & 16 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4059,25 +4059,31 @@ def _macro_delete(self, args: argparse.Namespace) -> None:
self.perror(f"Macro '{cur_name}' does not exist")

# macro -> list
macro_list_help = "list macros"
macro_list_description = Text.assemble(
"List specified macros in a reusable form that can be saved to a startup script to preserve macros across sessions.",
"\n\n",
"Without arguments, all macros will be listed.",
)
@classmethod
def _build_macro_list_parser(cls) -> Cmd2ArgumentParser:
macro_list_description = Text.assemble(
(
"List specified macros in a reusable form that can be saved to a startup script "
"to preserve macros across sessions."
),
"\n\n",
"Without arguments, all macros will be listed.",
)

macro_list_parser = argparse_custom.DEFAULT_ARGUMENT_PARSER(description=macro_list_description)
macro_list_parser.add_argument(
'names',
nargs=argparse.ZERO_OR_MORE,
help='macro(s) to list',
choices_provider=_get_macro_completion_items,
descriptive_headers=["Value"],
)
macro_list_parser = argparse_custom.DEFAULT_ARGUMENT_PARSER(description=macro_list_description)
macro_list_parser.add_argument(
'names',
nargs=argparse.ZERO_OR_MORE,
help='macro(s) to list',
choices_provider=cls._get_macro_completion_items,
descriptive_headers=["Value"],
)

return macro_list_parser

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

tokens_to_quote = constants.REDIRECTION_TOKENS
Expand Down