-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcommand.py
More file actions
173 lines (154 loc) · 6.09 KB
/
command.py
File metadata and controls
173 lines (154 loc) · 6.09 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import argparse
import sys
try:
from rich.console import Console
from handler import Handler
except KeyboardInterrupt:
print("\nAborted by user.")
sys.exit(1)
class Command:
def __init__(self, sephera_parser: argparse.ArgumentParser) -> None:
self.sephera_parser = sephera_parser
self.console = Console()
self.handler = Handler()
self.sub_command = self.sephera_parser.add_subparsers(dest = "command")
def setup(self) -> None:
try:
self._set_tree_command()
self._set_stats_command()
self._set_loc_command()
self._set_help_command()
self._set_update_command()
self._set_languages_supports_command()
self._set_version_command()
self._set_language_cfg_command()
args = self.sephera_parser.parse_args()
if args.command is None:
self.handler.show_usage(args = args)
except Exception as setup_error:
self.console.print(f"[red] Fatal error when setup command: {setup_error}")
sys.exit(1)
def _set_stats_command(self) -> None:
stats_parser = self.sub_command.add_parser("stats", help = "Stats all files, folders in your directory")
stats_parser.add_argument(
"--path",
type = str,
help = "Path to scan.(Default is current directory)",
default = "."
)
stats_parser.add_argument(
"--ignore",
type = str,
help = "Regex pattern to ignore files or folders (e.g --ignore '__pycache__|\\.git')",
default = None
)
stats_parser.add_argument(
"--chart",
type = str,
nargs = "?",
const = "SepheraChart",
help = "Create chart for your stat overview (e.g --chart '<MyChartSaveDir>')",
default = None
)
stats_parser.set_defaults(function = self.handler.stats_command_handler)
def _set_tree_command(self) -> None:
tree_command = self.sub_command.add_parser("tree", help = "List tree view all files")
tree_command.add_argument(
"--path",
type = str,
help = "Path to scan (Default is current directory)",
default = "."
)
tree_command.add_argument(
"--ignore",
type = str,
help = "Regex pattern to ignore files or folders (e.g. --ignore '__pycache__|\\.git')",
default = None
)
tree_command.add_argument(
"--chart",
type = str,
nargs = "?",
const = "SepheraChart",
help = "Create chart for your directory tree (e.g --chart '<MyChartSaveDir>')",
default = None
)
tree_command.set_defaults(function = self.handler.tree_command_handler)
def _set_loc_command(self) -> None:
loc_command = self.sub_command.add_parser("loc", help = "LOC your code in project. Quickly")
loc_command.add_argument(
"--path",
type = str,
help = "Path to your project.",
default = "."
)
loc_command.add_argument(
"--ignore",
action = "append",
type = str,
help = "Regex pattern to ignore files or folders (e.g. --ignore '__pycache__|\\.git')",
default = None
)
loc_command.add_argument(
"--json",
type = str,
nargs = "?",
const = "SepheraExport",
help = "Export LOC count to JSON file format. e.g --json ('<MySaveDir/myJson>')",
default = None
)
loc_command.add_argument(
"--md",
type = str,
nargs = "?",
const = "SepheraExport",
help = "Export LOC count to Markdown file format. e.g --md ('<MySaveDir/myMarkdown>')",
default = None
)
loc_command.set_defaults(function = self.handler.loc_command_handler)
def _set_help_command(self) -> None:
help_command = self.sub_command.add_parser("help", help = "Show help message")
help_command.add_argument(
"command",
nargs = "*",
help = "Display help about a command."
)
help_command.set_defaults(function = self.handler.help_command_handler)
def _set_update_command(self) -> None:
update_command = self.sub_command.add_parser("update", help = "Update Sephera if latest version is available")
update_command.set_defaults(function = self.handler.update_command_handler)
def _set_languages_supports_command(self) -> None:
languages_support_command = self.sub_command.add_parser(
"language-support", help = "Fetch languages Sephera can support for LOC count."
)
languages_support_command.add_argument(
"--list",
type = bool,
const = True,
nargs = "?",
help = "Show list of languages currently supported by Sephera."
)
languages_support_command.set_defaults(function = self.handler.fetch_languages_supports_handler)
def _set_version_command(self) -> None:
version_command = self.sub_command.add_parser(
"version", help = "Display Sephera version."
)
version_command.add_argument(
"--git",
type = bool,
const = True,
nargs = "?",
help = "Show the Sephera latest version on GitHub."
)
version_command.set_defaults(function = self.handler.version_command_handler)
def _set_language_cfg_command(self) -> None:
language_cfg_command = self.sub_command.add_parser(
"cfg-language"
)
language_cfg_command.add_argument(
"--global",
action = "store_true",
dest = "global_",
help = "Set the configuration for language detection and LOC count to global."
)
language_cfg_command.set_defaults(function = self.handler.language_cfg_handler)