Skip to content

Commit e03b8b8

Browse files
committed
Added a static factory method to build the parser for the echo command
1 parent 60020a6 commit e03b8b8

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

examples/getting_started.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,16 @@ def do_intro(
184184
)
185185
)
186186

187-
# do_echo parser
188-
echo_parser = cmd2.Cmd2ArgumentParser(description="Multiline command that echoes input.")
189-
echo_parser.add_argument("-u", "--upper", action="store_true", help="uppercase the output")
190-
echo_parser.add_argument("-r", "--repeat", type=int, default=1, help="output [n] times")
191-
echo_parser.add_argument("words", nargs="+", help="words to print")
192-
193-
@cmd2.with_argparser(echo_parser)
187+
@staticmethod
188+
def _build_echo_parser() -> cmd2.Cmd2ArgumentParser:
189+
"""Parser factory method for use with the echo command."""
190+
echo_parser = cmd2.Cmd2ArgumentParser(description="Multiline command that echoes input.")
191+
echo_parser.add_argument("-u", "--upper", action="store_true", help="uppercase the output")
192+
echo_parser.add_argument("-r", "--repeat", type=int, default=1, help="output [n] times")
193+
echo_parser.add_argument("words", nargs="+", help="words to print")
194+
return echo_parser
195+
196+
@cmd2.with_argparser(_build_echo_parser)
194197
def do_echo(self, args: argparse.Namespace) -> None:
195198
"""Multiline command."""
196199
output_str = " ".join(args.words)

0 commit comments

Comments
 (0)