MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / do_custom_parser

Method do_custom_parser

examples/read_input.py:84–99  ·  view source on GitHub ↗

Call read_input to use a custom history and an argument parser.

(self, _)

Source from the content-addressed store, hash-verified

82
83 @cmd2.with_category(EXAMPLE_COMMANDS)
84 def do_custom_parser(self, _) -> None:
85 """Call read_input to use a custom history and an argument parser."""
86 parser = cmd2.Cmd2ArgumentParser(prog="", description="An example parser")
87 parser.add_argument("-o", "--option", help="an optional arg")
88 parser.add_argument("arg_1", help="a choice for this arg", metavar="arg_1", choices=["my_choice", "your_choice"])
89 parser.add_argument("arg_2", help="path of something", completer=cmd2.Cmd.path_complete)
90
91 self.poutput("Tab completing with argument parser and using custom history")
92 self.poutput(parser.format_usage())
93
94 try:
95 input_str = self.read_input("> ", history=self.custom_history, parser=parser)
96 except EOFError:
97 pass
98 else:
99 self.custom_history.append(input_str)
100
101 @cmd2.with_category(EXAMPLE_COMMANDS)
102 def do_read_password(self, _) -> None:

Callers

nothing calls this directly

Calls 3

poutputMethod · 0.80
read_inputMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected