Debian Codegraph @

docs/source/vs_arguably/subcommands/README.rst

raw
1 ===========
2 Subcommands
3 ===========
4 Arguably parses the command tree based on ``__`` delimited function names.
5
6 .. code-block:: python
7
8 import arguably
9
10
11 @arguably.command
12 def ec2__start_instances(*instances):
13 """Start instances.
14
15 Args:
16 *instances: {instance}s to start
17 """
18 for inst in instances:
19 print(f"Starting {inst}")
20
21
22 @arguably.command
23 def ec2__stop_instances(*instances):
24 """Stop instances.
25
26 Args:
27 *instances: {instance}s to stop
28 """
29 for inst in instances:
30 print(f"Stopping {inst}")
31
32
33 if __name__ == "__main__":
34 arguably.run()
35
36 .. code-block:: console
37
38 $ python main.py ec2 --help
39 positional arguments:
40 command
41 start-instances start instances.
42 stop-instances stop instances.
43
44 Cyclopts handles the command tree by creating and registering recursive :class:`App <cyclopts.App>` objects:
45
46 .. code-block:: python
47
48 from cyclopts import App
49
50 app = App()
51 ec2 = app.command(App(name="ec2"))
52
53
54 @ec2.command
55 def start_instances(*instances):
56 """Start instances.
57
58 Args:
59 *instances: {instance}s to start
60 """
61 for inst in instances:
62 print(f"Starting {inst}")
63
64
65 @ec2.command
66 def stop_instances(*instances):
67 """Stop instances.
68
69 Args:
70 *instances: {instance}s to stop
71 """
72 for inst in instances:
73 print(f"Stopping {inst}")
74
75
76 if __name__ == "__main__":
77 app()
78
79 .. code-block:: console
80
81 $ python main.py ec2 --help
82 ╭─ Commands ───────────────────────────────────────────────────────────╮
83 │ start-instances start instances. │
84 │ stop-instances stop instances. │
85 ╰──────────────────────────────────────────────────────────────────────╯