|
47 | 47 | from . import constants |
48 | 48 | from . import plugin |
49 | 49 | from . import utils |
50 | | -from .argparse_custom import Cmd2ArgumentParser, CompletionItem |
| 50 | +from .argparse_custom import CompletionItem, DEFAULT_ARGUMENT_PARSER |
51 | 51 | from .clipboard import can_clip, get_paste_buffer, write_to_paste_buffer |
52 | 52 | from .decorators import with_argparser |
53 | 53 | from .history import History, HistoryItem |
@@ -2244,7 +2244,7 @@ def _alias_list(self, args: argparse.Namespace) -> None: |
2244 | 2244 | "An alias is a command that enables replacement of a word by another string.") |
2245 | 2245 | alias_epilog = ("See also:\n" |
2246 | 2246 | " macro") |
2247 | | - alias_parser = Cmd2ArgumentParser(description=alias_description, epilog=alias_epilog) |
| 2247 | + alias_parser = DEFAULT_ARGUMENT_PARSER(description=alias_description, epilog=alias_epilog) |
2248 | 2248 |
|
2249 | 2249 | # Add subcommands to alias |
2250 | 2250 | alias_subparsers = alias_parser.add_subparsers(dest='subcommand') |
@@ -2421,7 +2421,7 @@ def _macro_list(self, args: argparse.Namespace) -> None: |
2421 | 2421 | "A macro is similar to an alias, but it can contain argument placeholders.") |
2422 | 2422 | macro_epilog = ("See also:\n" |
2423 | 2423 | " alias") |
2424 | | - macro_parser = Cmd2ArgumentParser(description=macro_description, epilog=macro_epilog) |
| 2424 | + macro_parser = DEFAULT_ARGUMENT_PARSER(description=macro_description, epilog=macro_epilog) |
2425 | 2425 |
|
2426 | 2426 | # Add subcommands to macro |
2427 | 2427 | macro_subparsers = macro_parser.add_subparsers(dest='subcommand') |
@@ -2537,8 +2537,8 @@ def complete_help_subcommands(self, text: str, line: str, begidx: int, endidx: i |
2537 | 2537 | completer = AutoCompleter(argparser, self) |
2538 | 2538 | return completer.complete_subcommand_help(tokens, text, line, begidx, endidx) |
2539 | 2539 |
|
2540 | | - help_parser = Cmd2ArgumentParser(description="List available commands or provide " |
2541 | | - "detailed help for a specific command") |
| 2540 | + help_parser = DEFAULT_ARGUMENT_PARSER(description="List available commands or provide " |
| 2541 | + "detailed help for a specific command") |
2542 | 2542 | help_parser.add_argument('command', nargs=argparse.OPTIONAL, help="command to retrieve help for", |
2543 | 2543 | completer_method=complete_help_command) |
2544 | 2544 | help_parser.add_argument('subcommands', nargs=argparse.REMAINDER, help="subcommand(s) to retrieve help for", |
@@ -2707,21 +2707,21 @@ def _print_topics(self, header: str, cmds: List[str], verbose: bool) -> None: |
2707 | 2707 | command = '' |
2708 | 2708 | self.stdout.write("\n") |
2709 | 2709 |
|
2710 | | - @with_argparser(Cmd2ArgumentParser(description="List available shortcuts")) |
| 2710 | + @with_argparser(DEFAULT_ARGUMENT_PARSER(description="List available shortcuts")) |
2711 | 2711 | def do_shortcuts(self, _: argparse.Namespace) -> None: |
2712 | 2712 | """List available shortcuts""" |
2713 | 2713 | # Sort the shortcut tuples by name |
2714 | 2714 | sorted_shortcuts = sorted(self.statement_parser.shortcuts, key=lambda x: self.default_sort_key(x[0])) |
2715 | 2715 | result = "\n".join('{}: {}'.format(sc[0], sc[1]) for sc in sorted_shortcuts) |
2716 | 2716 | self.poutput("Shortcuts for other commands:\n{}".format(result)) |
2717 | 2717 |
|
2718 | | - @with_argparser(Cmd2ArgumentParser(epilog=INTERNAL_COMMAND_EPILOG)) |
| 2718 | + @with_argparser(DEFAULT_ARGUMENT_PARSER(epilog=INTERNAL_COMMAND_EPILOG)) |
2719 | 2719 | def do_eof(self, _: argparse.Namespace) -> bool: |
2720 | 2720 | """Called when <Ctrl>-D is pressed""" |
2721 | 2721 | # Return True to stop the command loop |
2722 | 2722 | return True |
2723 | 2723 |
|
2724 | | - @with_argparser(Cmd2ArgumentParser(description="Exit this application")) |
| 2724 | + @with_argparser(DEFAULT_ARGUMENT_PARSER(description="Exit this application")) |
2725 | 2725 | def do_quit(self, _: argparse.Namespace) -> bool: |
2726 | 2726 | """Exit this application""" |
2727 | 2727 | # Return True to stop the command loop |
@@ -2824,7 +2824,7 @@ def _show(self, args: argparse.Namespace, parameter: str = '') -> None: |
2824 | 2824 | "Accepts abbreviated parameter names so long as there is no ambiguity.\n" |
2825 | 2825 | "Call without arguments for a list of settable parameters with their values.") |
2826 | 2826 |
|
2827 | | - set_parser = Cmd2ArgumentParser(description=set_description) |
| 2827 | + set_parser = DEFAULT_ARGUMENT_PARSER(description=set_description) |
2828 | 2828 | set_parser.add_argument('-a', '--all', action='store_true', help='display read-only settings as well') |
2829 | 2829 | set_parser.add_argument('-l', '--long', action='store_true', help='describe function of parameter') |
2830 | 2830 | set_parser.add_argument('param', nargs=argparse.OPTIONAL, help='parameter to set or view', |
@@ -2869,7 +2869,7 @@ def do_set(self, args: argparse.Namespace) -> None: |
2869 | 2869 | if onchange_hook is not None: |
2870 | 2870 | onchange_hook(old=orig_value, new=new_value) # pylint: disable=not-callable |
2871 | 2871 |
|
2872 | | - shell_parser = Cmd2ArgumentParser(description="Execute a command as if at the OS prompt") |
| 2872 | + shell_parser = DEFAULT_ARGUMENT_PARSER(description="Execute a command as if at the OS prompt") |
2873 | 2873 | shell_parser.add_argument('command', help='the command to run', completer_method=shell_cmd_complete) |
2874 | 2874 | shell_parser.add_argument('command_args', nargs=argparse.REMAINDER, help='arguments to pass to command', |
2875 | 2875 | completer_method=path_complete) |
@@ -3034,7 +3034,7 @@ def _restore_cmd2_env(self, cmd2_env: _SavedCmd2Env) -> None: |
3034 | 3034 | "If you see strange parsing behavior, it's best to just open the Python shell\n" |
3035 | 3035 | "by providing no arguments to py and run more complex statements there.") |
3036 | 3036 |
|
3037 | | - py_parser = Cmd2ArgumentParser(description=py_description) |
| 3037 | + py_parser = DEFAULT_ARGUMENT_PARSER(description=py_description) |
3038 | 3038 | py_parser.add_argument('command', nargs=argparse.OPTIONAL, help="command to run") |
3039 | 3039 | py_parser.add_argument('remainder', nargs=argparse.REMAINDER, help="remainder of command") |
3040 | 3040 |
|
@@ -3156,7 +3156,7 @@ def py_quit(): |
3156 | 3156 |
|
3157 | 3157 | return py_bridge.stop |
3158 | 3158 |
|
3159 | | - run_pyscript_parser = Cmd2ArgumentParser(description="Run a Python script file inside the console") |
| 3159 | + run_pyscript_parser = DEFAULT_ARGUMENT_PARSER(description="Run a Python script file inside the console") |
3160 | 3160 | run_pyscript_parser.add_argument('script_path', help='path to the script file', completer_method=path_complete) |
3161 | 3161 | run_pyscript_parser.add_argument('script_arguments', nargs=argparse.REMAINDER, |
3162 | 3162 | help='arguments to pass to script', completer_method=path_complete) |
@@ -3201,7 +3201,7 @@ def do_run_pyscript(self, args: argparse.Namespace) -> Optional[bool]: |
3201 | 3201 |
|
3202 | 3202 | # Only include the do_ipy() method if IPython is available on the system |
3203 | 3203 | if ipython_available: # pragma: no cover |
3204 | | - @with_argparser(Cmd2ArgumentParser(description="Enter an interactive IPython shell")) |
| 3204 | + @with_argparser(DEFAULT_ARGUMENT_PARSER(description="Enter an interactive IPython shell")) |
3205 | 3205 | def do_ipy(self, _: argparse.Namespace) -> None: |
3206 | 3206 | """Enter an interactive IPython shell""" |
3207 | 3207 | from .py_bridge import PyBridge |
@@ -3232,7 +3232,7 @@ def load_ipy(cmd2_app: Cmd, py_bridge: PyBridge): |
3232 | 3232 |
|
3233 | 3233 | history_description = "View, run, edit, save, or clear previously entered commands" |
3234 | 3234 |
|
3235 | | - history_parser = Cmd2ArgumentParser(description=history_description) |
| 3235 | + history_parser = DEFAULT_ARGUMENT_PARSER(description=history_description) |
3236 | 3236 | history_action_group = history_parser.add_mutually_exclusive_group() |
3237 | 3237 | history_action_group.add_argument('-r', '--run', action='store_true', help='run selected history items') |
3238 | 3238 | history_action_group.add_argument('-e', '--edit', action='store_true', |
@@ -3543,7 +3543,7 @@ def _generate_transcript(self, history: List[Union[HistoryItem, str]], transcrip |
3543 | 3543 | "\n" |
3544 | 3544 | " set editor (program-name)") |
3545 | 3545 |
|
3546 | | - edit_parser = Cmd2ArgumentParser(description=edit_description) |
| 3546 | + edit_parser = DEFAULT_ARGUMENT_PARSER(description=edit_description) |
3547 | 3547 | edit_parser.add_argument('file_path', nargs=argparse.OPTIONAL, |
3548 | 3548 | help="optional path to a file to open in editor", completer_method=path_complete) |
3549 | 3549 |
|
@@ -3584,7 +3584,7 @@ def _current_script_dir(self) -> Optional[str]: |
3584 | 3584 | "If the -t/--transcript flag is used, this command instead records\n" |
3585 | 3585 | "the output of the script commands to a transcript for testing purposes.\n") |
3586 | 3586 |
|
3587 | | - run_script_parser = Cmd2ArgumentParser(description=run_script_description) |
| 3587 | + run_script_parser = DEFAULT_ARGUMENT_PARSER(description=run_script_description) |
3588 | 3588 | run_script_parser.add_argument('-t', '--transcript', metavar='TRANSCRIPT_FILE', |
3589 | 3589 | help='record the output of the script as a transcript file', |
3590 | 3590 | completer_method=path_complete) |
@@ -3658,8 +3658,8 @@ def do_run_script(self, args: argparse.Namespace) -> Optional[bool]: |
3658 | 3658 | relative_run_script_epilog = ("Notes:\n" |
3659 | 3659 | " This command is intended to only be used within text file scripts.") |
3660 | 3660 |
|
3661 | | - relative_run_script_parser = Cmd2ArgumentParser(description=relative_run_script_description, |
3662 | | - epilog=relative_run_script_epilog) |
| 3661 | + relative_run_script_parser = DEFAULT_ARGUMENT_PARSER(description=relative_run_script_description, |
| 3662 | + epilog=relative_run_script_epilog) |
3663 | 3663 | relative_run_script_parser.add_argument('file_path', help='a file path pointing to a script') |
3664 | 3664 |
|
3665 | 3665 | @with_argparser(relative_run_script_parser) |
|
0 commit comments