-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript5.py
More file actions
executable file
·49 lines (30 loc) · 1.15 KB
/
Copy pathscript5.py
File metadata and controls
executable file
·49 lines (30 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
from clak import Argument, Command, Parser
# Base action class for reusability
class AppSubAction(Parser):
"Default action to illustrate subcommand reusability"
def cli_run(self, args, **_):
print(f"Command called with args: {args}")
# Level 3 commands
class SubSubCommand2a(AppSubAction):
"SubSubCommand2a"
args = Argument("ARGS", nargs="+", help="One or more arguments")
class SubSubCommand2b(Parser):
"SubSubCommand2b"
args = Argument("ARGS", nargs="*", help="Zero or more arguments")
# Level 2 commands
class SubCommand1(AppSubAction):
"SubCommand1"
args = Argument("ARGS", nargs="*", help="Zero or more arguments")
class SubCommand2(AppSubAction):
"SubCommand2"
sub2a = Command(SubSubCommand2a)
sub2b = Command(SubSubCommand2b)
class AppMain(Parser):
"""Demo application with deep nested commands"""
debug = Argument("--debug", action="store_true", help="Enable debug mode")
config = Argument("--config", "-c", help="Config file path", default="config.yaml")
sub1 = Command(SubCommand1)
sub2 = Command(SubCommand2)
if __name__ == "__main__":
AppMain()