Skip to content

Commit bbfab98

Browse files
committed
Removed Cmd2ArgumentParser.add_subparsers() override.
1 parent 40bf34a commit bbfab98

4 files changed

Lines changed: 6 additions & 22 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ prompt is displayed.
7878
the Enhancements section below for details).
7979
- Removed `Cmd.undoc_header` since all commands are now considered categorized.
8080
- Renamed `Cmd.cmd_func()` to `Cmd.get_command_func()`.
81+
- `cmd2` no longer sets a default title for a subparsers group. If you desire a title, you will
82+
need to pass one in like this `parser.add_subparsers(title="subcommands")`. This is standard
83+
`argparse` behavior.
8184
- Enhancements
8285
- New `cmd2.Cmd` parameters
8386
- **auto_suggest**: (boolean) if `True`, provide fish shell style auto-suggestions. These

cmd2/argparse_custom.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -772,25 +772,6 @@ def __init__(
772772
self.description: RenderableType | None # type: ignore[assignment]
773773
self.epilog: RenderableType | None # type: ignore[assignment]
774774

775-
def add_subparsers( # type: ignore[override]
776-
self,
777-
**kwargs: Any,
778-
) -> "argparse._SubParsersAction[Cmd2ArgumentParser]":
779-
"""Override for improved defaults and type safety.
780-
781-
This override does two things.
782-
1. Sets a default title if one was not given.
783-
2. Narrows the return type to provide better IDE autocompletion
784-
and type safety for `Cmd2ArgumentParser` instances.
785-
786-
:param kwargs: additional keyword arguments
787-
:return: _SubParsersAction which stores Cmd2ArgumentParsers
788-
"""
789-
if 'title' not in kwargs:
790-
kwargs['title'] = 'subcommands'
791-
792-
return super().add_subparsers(**kwargs)
793-
794775
def _get_subparsers_action(self) -> "argparse._SubParsersAction[Cmd2ArgumentParser]":
795776
"""Get the _SubParsersAction for this parser if it exists.
796777

cmd2/cmd2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3728,7 +3728,7 @@ def _build_alias_parser() -> Cmd2ArgumentParser:
37283728
"See Also",
37293729
"macro",
37303730
)
3731-
alias_parser.add_subparsers(metavar='SUBCOMMAND', required=True)
3731+
alias_parser.add_subparsers(title="subcommands", metavar="SUBCOMMAND", required=True)
37323732

37333733
return alias_parser
37343734

@@ -3944,7 +3944,7 @@ def _build_macro_parser() -> Cmd2ArgumentParser:
39443944
"See Also",
39453945
"alias",
39463946
)
3947-
macro_parser.add_subparsers(metavar='SUBCOMMAND', required=True)
3947+
macro_parser.add_subparsers(title="subcommands", metavar="SUBCOMMAND", required=True)
39483948

39493949
return macro_parser
39503950

cmd2/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def as_subcommand_to(
370370
Example:
371371
```py
372372
base_parser = cmd2.Cmd2ArgumentParser()
373-
base_parser.add_subparsers(metavar='SUBCOMMAND', required=True)
373+
base_parser.add_subparsers(title="subcommands", metavar="SUBCOMMAND", required=True)
374374
sub_parser = cmd2.Cmd2ArgumentParser()
375375
376376
class MyApp(cmd2.Cmd):

0 commit comments

Comments
 (0)