-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcul.py
More file actions
204 lines (171 loc) · 6.76 KB
/
Copy pathcul.py
File metadata and controls
204 lines (171 loc) · 6.76 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import sys
from colorful_outputs import print_in_red
from cache_and_install import show_cache, clear_cache
from install_module_2 import install
from uninstall_module import uninstall
from update_module import update
from freeze_requirements import freeze, list_modules
from search_module import search_module, fuzzy_search_module
from init import init
from helper_functions import handle_req_file_ops
from cul_help import help_message
from change_registry import change_reg
from file_ops import add_file, remove_file
from compile import compile_files
from version_handling import increment_major, increment_minor, increment_patch
def main():
# Check if the user has provided a command
if len(sys.argv) < 2:
help_message()
return
command = sys.argv[1]
match command:
case 'install':
if len(sys.argv) < 3:
print_in_red("Error: No library specified for installation.")
help_message("install")
return
registry = None
module_end = len(sys.argv)
if '--use-reg' in sys.argv:
reg_index = sys.argv.index('--use-reg')
if reg_index + 1 >= len(sys.argv):
print_in_red("Error: No registry link was provided")
help_message("install")
return
registry = sys.argv[reg_index + 1]
module_end = reg_index
if sys.argv[2] == '-r':
if len(sys.argv) < 4:
print_in_red("Error: No requirements file specified for installation.")
help_message("install")
return
handle_req_file_ops(sys.argv[3], install, registry)
else:
for i in range(2, module_end):
install(sys.argv[i], registry)
case 'uninstall':
if len(sys.argv) < 3:
print_in_red("Error: No library specified for uninstallation.")
help_message("uninstall")
return
if sys.argv[2] == '-r':
if len(sys.argv) < 4:
print_in_red("Error: No requirements file specified for uninstallation.")
help_message("uninstall")
return
handle_req_file_ops(sys.argv[3], uninstall)
else:
for i in range(2, len(sys.argv)):
uninstall(sys.argv[i])
case 'update':
if len(sys.argv) < 3:
print_in_red("Error: No library specified for updating.")
help_message("update")
return
registry = None
module_end = len(sys.argv)
if '--use-reg' in sys.argv:
reg_index = sys.argv.index('--use-reg')
if reg_index + 1 >= len(sys.argv):
print_in_red("Error: No registry link was provided")
help_message("update")
return
registry = sys.argv[reg_index + 1]
module_end = reg_index
if sys.argv[2] == '-r':
if len(sys.argv) < 4:
print_in_red("Error: No requirements file specified for installation.")
help_message("update")
return
handle_req_file_ops(sys.argv[3], update, registry)
else:
for i in range(2, module_end):
update(sys.argv[i], registry)
case 'help':
if len(sys.argv) < 3:
help_message()
return
help_message(sys.argv[2])
case 'freeze':
freeze()
case 'list':
list_modules()
case 'search':
if sys.argv[-1] == "--use-reg":
print_in_red("Error: No registry link was provided")
help_message("search")
return
registry = ''
if sys.argv[-2] == '--use-reg':
registry = sys.argv[-1]
if sys.argv[2] == '--fuzzy':
if len(sys.argv) < 4:
print_in_red("Error: No library specified for searching.")
help_message("search")
return
fuzzy_search_module(query=sys.argv[3], called_by_user=True, registry=registry)
return
if len(sys.argv) < 3:
print_in_red("Error: No library specified for searching.")
help_message("search")
return
search_module(sys.argv[2], registry)
case 'cache':
if len(sys.argv) < 3:
print_in_red("Error: No command specified related to cache.")
help_message("cache")
return
match sys.argv[2]:
case 'clear':
clear_cache()
case 'show':
show_cache()
case _:
print_in_red(f"Unknown cache command: {sys.argv[2]}")
help_message("cache")
case 'init':
init(True if len(sys.argv) > 2 and sys.argv[2] == '-y' else False)
case 'set-reg':
if len(sys.argv) < 3:
print_in_red("Error: No registry link was provided")
help_message("set_reg")
return
change_reg(sys.argv[2])
case 'new':
if len(sys.argv) < 3:
print_in_red("Error: No file name provided for creating a new file.")
help_message("new")
return
add_file(sys.argv[2])
case 'remove':
if len(sys.argv) < 3:
print_in_red("Error: No file name provided for removing a file.")
help_message("remove")
return
delete_file = False
if len(sys.argv) > 3 and sys.argv[3] == '--delete':
delete_file = True
remove_file(sys.argv[2], delete_file)
case 'compile':
compile_files()
case 'version':
if len(sys.argv) < 3:
print_in_red("Error: No version command specified.")
help_message()
return
match sys.argv[2]:
case 'major':
increment_major()
case 'minor':
increment_minor()
case 'patch':
increment_patch()
case _:
print_in_red(f"Unknown version command: {sys.argv[2]}")
help_message("version")
case _:
print_in_red(f"Unknown command: {command}")
help_message()
if __name__ == "__main__":
main()