Skip to content

Commit b093bc9

Browse files
committed
Switch from Group to Text.assemble() when building help text.
1 parent a5545b8 commit b093bc9

File tree

1 file changed

+41
-43
lines changed

1 file changed

+41
-43
lines changed

cmd2/cmd2.py

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,9 +3508,9 @@ def _cmdloop(self) -> None:
35083508
# Top-level parser for alias
35093509
@staticmethod
35103510
def _build_alias_parser() -> Cmd2ArgumentParser:
3511-
alias_description = Group(
3511+
alias_description = Text.assemble(
35123512
"Manage aliases.",
3513-
"\n",
3513+
"\n\n",
35143514
"An alias is a command that enables replacement of a word by another string.",
35153515
)
35163516
alias_parser = argparse_custom.DEFAULT_ARGUMENT_PARSER(description=alias_description)
@@ -3537,10 +3537,11 @@ def _build_alias_create_parser(cls) -> Cmd2ArgumentParser:
35373537
alias_create_parser = argparse_custom.DEFAULT_ARGUMENT_PARSER(description=alias_create_description)
35383538

35393539
# Add Notes epilog
3540-
alias_create_notes = Group(
3540+
alias_create_notes = Text.assemble(
35413541
"If you want to use redirection, pipes, or terminators in the value of the alias, then quote them.",
3542-
"\n",
3543-
Text(" alias create save_results print_results \">\" out.txt\n", style=Cmd2Style.COMMAND_LINE),
3542+
"\n\n",
3543+
(" alias create save_results print_results \">\" out.txt\n", Cmd2Style.COMMAND_LINE),
3544+
"\n\n",
35443545
(
35453546
"Since aliases are resolved during parsing, tab completion will function as it would "
35463547
"for the actual command the alias resolves to."
@@ -3639,12 +3640,12 @@ def _alias_delete(self, args: argparse.Namespace) -> None:
36393640
# alias -> list
36403641
@classmethod
36413642
def _build_alias_list_parser(cls) -> Cmd2ArgumentParser:
3642-
alias_list_description = Group(
3643+
alias_list_description = Text.assemble(
36433644
(
36443645
"List specified aliases in a reusable form that can be saved to a startup "
36453646
"script to preserve aliases across sessions."
36463647
),
3647-
"\n",
3648+
"\n\n",
36483649
"Without arguments, all aliases will be listed.",
36493650
)
36503651

@@ -3719,9 +3720,9 @@ def macro_arg_complete(
37193720
# Top-level parser for macro
37203721
@staticmethod
37213722
def _build_macro_parser() -> Cmd2ArgumentParser:
3722-
macro_description = Group(
3723+
macro_description = Text.assemble(
37233724
"Manage macros.",
3724-
"\n",
3725+
"\n\n",
37253726
"A macro is similar to an alias, but it can contain argument placeholders.",
37263727
)
37273728
macro_parser = argparse_custom.DEFAULT_ARGUMENT_PARSER(description=macro_description)
@@ -3744,48 +3745,46 @@ def do_macro(self, args: argparse.Namespace) -> None:
37443745
# macro -> create
37453746
@classmethod
37463747
def _build_macro_create_parser(cls) -> Cmd2ArgumentParser:
3747-
macro_create_description = Group(
3748+
macro_create_description = Text.assemble(
37483749
"Create or overwrite a macro.",
3749-
"\n",
3750+
"\n\n",
37503751
"A macro is similar to an alias, but it can contain argument placeholders.",
3751-
"\n",
3752+
"\n\n",
37523753
"Arguments are expressed when creating a macro using {#} notation where {1} means the first argument.",
3753-
"\n",
3754+
"\n\n",
37543755
"The following creates a macro called my_macro that expects two arguments:",
3755-
"\n",
3756-
Text(" macro create my_macro make_dinner --meat {1} --veggie {2}", style=Cmd2Style.COMMAND_LINE),
3757-
"\n",
3756+
"\n\n",
3757+
(" macro create my_macro make_dinner --meat {1} --veggie {2}", Cmd2Style.COMMAND_LINE),
3758+
"\n\n",
37583759
"When the macro is called, the provided arguments are resolved and the assembled command is run. For example:",
3759-
"\n",
3760-
Text.assemble(
3761-
(" my_macro beef broccoli", Cmd2Style.COMMAND_LINE),
3762-
(" ───> ", Style(bold=True)),
3763-
("make_dinner --meat beef --veggie broccoli", Cmd2Style.COMMAND_LINE),
3764-
),
3760+
"\n\n",
3761+
(" my_macro beef broccoli", Cmd2Style.COMMAND_LINE),
3762+
(" ───> ", Style(bold=True)),
3763+
("make_dinner --meat beef --veggie broccoli", Cmd2Style.COMMAND_LINE),
37653764
)
37663765
macro_create_parser = argparse_custom.DEFAULT_ARGUMENT_PARSER(description=macro_create_description)
37673766

37683767
# Add Notes epilog
3769-
macro_create_notes = Group(
3768+
macro_create_notes = Text.assemble(
37703769
"To use the literal string {1} in your command, escape it this way: {{1}}.",
3771-
"\n",
3770+
"\n\n",
37723771
"Extra arguments passed to a macro are appended to resolved command.",
3773-
"\n",
3772+
"\n\n",
37743773
(
37753774
"An argument number can be repeated in a macro. In the following example the "
37763775
"first argument will populate both {1} instances."
37773776
),
3778-
"\n",
3779-
Text(" macro create ft file_taxes -p {1} -q {2} -r {1}", style=Cmd2Style.COMMAND_LINE),
3780-
"\n",
3777+
"\n\n",
3778+
(" macro create ft file_taxes -p {1} -q {2} -r {1}", Cmd2Style.COMMAND_LINE),
3779+
"\n\n",
37813780
"To quote an argument in the resolved command, quote it during creation.",
3782-
"\n",
3783-
Text(" macro create backup !cp \"{1}\" \"{1}.orig\"", style=Cmd2Style.COMMAND_LINE),
3784-
"\n",
3781+
"\n\n",
3782+
(" macro create backup !cp \"{1}\" \"{1}.orig\"", Cmd2Style.COMMAND_LINE),
3783+
"\n\n",
37853784
"If you want to use redirection, pipes, or terminators in the value of the macro, then quote them.",
3786-
"\n",
3787-
Text(" macro create show_results print_results -type {1} \"|\" less", style=Cmd2Style.COMMAND_LINE),
3788-
"\n",
3785+
"\n\n",
3786+
(" macro create show_results print_results -type {1} \"|\" less", Cmd2Style.COMMAND_LINE),
3787+
"\n\n",
37893788
(
37903789
"Since macros don't resolve until after you press Enter, their arguments tab complete as paths. "
37913790
"This default behavior changes if custom tab completion for macro arguments has been implemented."
@@ -3926,11 +3925,10 @@ def _macro_delete(self, args: argparse.Namespace) -> None:
39263925

39273926
# macro -> list
39283927
macro_list_help = "list macros"
3929-
macro_list_description = (
3930-
"List specified macros in a reusable form that can be saved to a startup script\n"
3931-
"to preserve macros across sessions\n"
3932-
"\n"
3933-
"Without arguments, all macros will be listed."
3928+
macro_list_description = Text.assemble(
3929+
"List specified macros in a reusable form that can be saved to a startup script to preserve macros across sessions.",
3930+
"\n\n",
3931+
"Without arguments, all macros will be listed.",
39343932
)
39353933

39363934
macro_list_parser = argparse_custom.DEFAULT_ARGUMENT_PARSER(description=macro_list_description)
@@ -4385,9 +4383,9 @@ def select(self, opts: str | list[str] | list[tuple[Any, str | None]], prompt: s
43854383
def _build_base_set_parser(cls) -> Cmd2ArgumentParser:
43864384
# When tab completing value, we recreate the set command parser with a value argument specific to
43874385
# the settable being edited. To make this easier, define a base parser with all the common elements.
4388-
set_description = Group(
4386+
set_description = Text.assemble(
43894387
"Set a settable parameter or show current settings of parameters.",
4390-
"\n",
4388+
"\n\n",
43914389
(
43924390
"Call without arguments for a list of all settable parameters with their values. "
43934391
"Call with just param to view that parameter's value."
@@ -5380,9 +5378,9 @@ def _current_script_dir(self) -> str | None:
53805378

53815379
@classmethod
53825380
def _build_base_run_script_parser(cls) -> Cmd2ArgumentParser:
5383-
run_script_description = Group(
5381+
run_script_description = Text.assemble(
53845382
"Run text script.",
5385-
"\n",
5383+
"\n\n",
53865384
"Scripts should contain one command per line, entered as you would in the console.",
53875385
)
53885386

0 commit comments

Comments
 (0)