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

Class CommandSetA

tests/test_commandset.py:28–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26
27
28class CommandSetA(CommandSetBase):
29 DEFAULT_CATEGORY = "Fruits"
30
31 def on_register(self, cmd) -> None:
32 super().on_register(cmd)
33 print("in on_register now")
34
35 def on_registered(self) -> None:
36 super().on_registered()
37 print("in on_registered now")
38
39 def on_unregister(self) -> None:
40 super().on_unregister()
41 print("in on_unregister now")
42
43 def on_unregistered(self) -> None:
44 super().on_unregistered()
45 print("in on_unregistered now")
46
47 def do_apple(self, statement: cmd2.Statement) -> None:
48 """Apple Command"""
49 self._cmd.poutput("Apple!")
50
51 def do_banana(self, statement: cmd2.Statement) -> None:
52 """Banana Command"""
53 self._cmd.poutput("Banana!!")
54
55 cranberry_parser = cmd2.Cmd2ArgumentParser()
56 cranberry_parser.add_argument("arg1", choices=["lemonade", "juice", "sauce"])
57
58 @cmd2.with_argparser(cranberry_parser, with_unknown_args=True)
59 def do_cranberry(self, ns: argparse.Namespace, unknown: list[str]) -> None:
60 """Cranberry Command"""
61 self._cmd.poutput(f"Cranberry {ns.arg1}!!")
62 if unknown and len(unknown):
63 self._cmd.poutput("Unknown: " + ", ".join(["{}"] * len(unknown)).format(*unknown))
64 self._cmd.last_result = {"arg1": ns.arg1, "unknown": unknown}
65
66 def help_cranberry(self) -> None:
67 self._cmd.stdout.write("This command does diddly squat...\n")
68
69 @cmd2.with_argument_list
70 @cmd2.with_category("Also Alone")
71 def do_durian(self, args: list[str]) -> None:
72 """Durian Command"""
73 self._cmd.poutput(f"{len(args)} Arguments: ")
74 self._cmd.poutput(", ".join(["{}"] * len(args)).format(*args))
75 self._cmd.last_result = {"args": args}
76
77 def complete_durian(self, text: str, line: str, begidx: int, endidx: int) -> list[str]:
78 return self._cmd.basic_complete(text, line, begidx, endidx, ["stinks", "smells", "disgusting"])
79
80 elderberry_parser = cmd2.Cmd2ArgumentParser()
81 elderberry_parser.add_argument("arg1")
82
83 @cmd2.with_category("Alone")
84 @cmd2.with_argparser(elderberry_parser)
85 def do_elderberry(self, ns: argparse.Namespace) -> None:

Callers 3

test_load_commandsFunction · 0.70

Calls

no outgoing calls

Tested by 3

test_load_commandsFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…