-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript3.py
More file actions
executable file
·38 lines (25 loc) · 1.3 KB
/
Copy pathscript3.py
File metadata and controls
executable file
·38 lines (25 loc) · 1.3 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
#!/usr/bin/env python3
from clak import Argument, Command, Parser
class AppCommand1(Parser): # (1)!
"Command 1, which says hello"
force = Argument("--force", "-f", action="store_true", help="Force") # (2)!
def cli_run(self, force=None, **_): # (3)!
force = "with the force" if force else "without the force"
print(f"Run Command 1: Hello {force}")
class AppCommand2(Parser): # (4)!
"Command 2, with option and positional arguments"
aliases = Argument("--alias", "-a", action="append", help="Alias") # (5)!
name = Argument("NAME", help="Name")
def cli_run(self, name=None, aliases=None, force=False, config=None, **_): # (6)!
print(f"Run command 2 World on: {name} in '{config}' file (force_mode={force})")
for alias in aliases or []:
print(f"Map: {alias} -> {name}")
class AppMain(Parser): # (7)!
"""Demo application with options and two subcommands."""
debug = Argument("--debug", action="store_true", help="Enable debug mode") # (8)!
config = Argument("--config", "-c", help="Config file path", default="config.yaml")
# Define subcommands
command1 = Command(AppCommand1, help="Execute command 1") # (9)!
command2 = Command(AppCommand2, help="Execute command 2") # (10)!
if __name__ == "__main__":
AppMain()