Skip to content

Commit d4a2e9c

Browse files
committed
Created CLI click groups
Added a CustomGroup class from which the rest of groups inherit Added Builder and Manager groups and added them to a CLI group on __main__.py
1 parent 230158c commit d4a2e9c

File tree

4 files changed

+164
-0
lines changed

4 files changed

+164
-0
lines changed

src/__main__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from click import group
2+
3+
from .cli.builder import Builder
4+
from .cli.manager import Manager
5+
6+
7+
@group()
8+
def cli() -> None:
9+
pass
10+
11+
cli.add_command(Builder())
12+
cli.add_command(Manager())
13+
14+
15+
def main() -> None:
16+
cli()
17+
18+
19+
if __name__ == "__main__":
20+
main()

src/cli/builder.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import inspect
2+
3+
from click import Command, Option
4+
from InquirerPy import inquirer
5+
from InquirerPy.validator import EmptyInputValidator
6+
7+
from .custom_group import CustomGroup
8+
9+
10+
class Builder(CustomGroup):
11+
12+
def __init__(self) -> None:
13+
super().__init__()
14+
15+
def create(self) -> Command:
16+
17+
help = ""
18+
options = [
19+
Option()
20+
]
21+
22+
def callback() -> None:
23+
pass
24+
25+
return Command(
26+
name=inspect.currentframe().f_code.co_name, # type: ignore
27+
help=help,
28+
callback=callback,
29+
params=options # type: ignore
30+
)
31+
32+
def update(self) -> Command:
33+
34+
help = ""
35+
options = [
36+
Option()
37+
]
38+
39+
def callback() -> None:
40+
pass
41+
42+
return Command(
43+
name = inspect.currentframe().f_code.co_name, # type: ignore
44+
help=help,
45+
callback=callback,
46+
params=options # type: ignore
47+
)

src/cli/custom_group.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import inspect
2+
3+
from click import Group, Command
4+
5+
6+
class CustomGroup(Group):
7+
8+
def __init__(self) -> None:
9+
super().__init__()
10+
self.__register_commands()
11+
12+
def __register_commands(self) -> None:
13+
for _, method in inspect.getmembers(self, predicate=inspect.ismethod):
14+
result = method()
15+
if isinstance(result, Command):
16+
self.add_command(result)

src/cli/manager.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import inspect
2+
3+
from click import Command, Option
4+
from InquirerPy import inquirer
5+
from InquirerPy.validator import EmptyInputValidator
6+
7+
from .custom_group import CustomGroup
8+
9+
10+
class Manager(CustomGroup):
11+
12+
def __init__(self) -> None:
13+
super().__init__()
14+
15+
def bakcup(self) -> Command:
16+
17+
help = ""
18+
options = [
19+
Option()
20+
]
21+
22+
def callback() -> None:
23+
pass
24+
25+
return Command(
26+
name=inspect.currentframe().f_code.co_name, # type: ignore
27+
help=help,
28+
callback=callback,
29+
params=options # type: ignore
30+
)
31+
32+
def delete(self) -> Command:
33+
34+
help = ""
35+
options = [
36+
Option()
37+
]
38+
39+
def callback() -> None:
40+
pass
41+
42+
return Command(
43+
name = inspect.currentframe().f_code.co_name, # type: ignore
44+
help=help,
45+
callback=callback,
46+
params=options # type: ignore
47+
)
48+
49+
def start(self) -> Command:
50+
51+
help = ""
52+
options = [
53+
Option()
54+
]
55+
56+
def callback() -> None:
57+
pass
58+
59+
return Command(
60+
name=inspect.currentframe().f_code.co_name, # type: ignore
61+
help=help,
62+
callback=callback,
63+
params=options # type: ignore
64+
)
65+
66+
def stop(self) -> Command:
67+
68+
help = ""
69+
options = [
70+
Option()
71+
]
72+
73+
def callback() -> None:
74+
pass
75+
76+
return Command(
77+
name=inspect.currentframe().f_code.co_name, # type: ignore
78+
help=help,
79+
callback=callback,
80+
params=options # type: ignore
81+
)

0 commit comments

Comments
 (0)