Skip to content

Commit 7fa6cbb

Browse files
committed
Refactored default_categories example to use parent parser factories and forward Statement objects
1 parent 6d9a632 commit 7fa6cbb

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

examples/default_categories.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import cmd2
1515
from cmd2 import (
16-
Cmd2ArgumentParser,
1716
CommandSet,
1817
with_argparser,
1918
with_category,
@@ -48,16 +47,16 @@ def do_app_command(self, _: cmd2.Statement) -> None:
4847
"""A standard command defined in the child class."""
4948
self.poutput("Application command executed")
5049

51-
@with_argparser(Cmd2ArgumentParser(description="Overridden quit command"))
52-
def do_quit(self, _: argparse.Namespace) -> bool | None:
50+
@with_argparser(cmd2.Cmd._build_quit_parser)
51+
def do_quit(self, args: argparse.Namespace) -> bool | None:
5352
"""Overriding a built-in command without a decorator moves it to our category."""
54-
return super().do_quit("")
53+
return super().do_quit(args.cmd2_statement)
5554

5655
@with_category(cmd2.Cmd.DEFAULT_CATEGORY)
57-
@with_argparser(Cmd2ArgumentParser(description="Overridden shortcuts command"))
58-
def do_shortcuts(self, _: argparse.Namespace) -> None:
56+
@with_argparser(cmd2.Cmd._build_shortcuts_parser)
57+
def do_shortcuts(self, args: argparse.Namespace) -> None:
5958
"""Overriding with @with_category(cmd2.Cmd.DEFAULT_CATEGORY) keeps it cmd2's category."""
60-
super().do_shortcuts("")
59+
super().do_shortcuts(args.cmd2_statement)
6160

6261

6362
if __name__ == "__main__":

0 commit comments

Comments
 (0)