4
4
from .utils import Package , Repo , Test
5
5
6
6
repo = typer .Typer ()
7
+ repo_remote = typer .Typer ()
8
+ repo .add_typer (repo_remote , name = "remote" )
7
9
8
10
9
11
def repo_command (
@@ -33,52 +35,153 @@ def main(
33
35
list_repos : bool = typer .Option (
34
36
False , "--list-repos" , "-l" , help = "List available repositories."
35
37
),
38
+ quiet : bool = typer .Option (
39
+ False , "--quiet" , "-q" , help = "Suppress output messages."
40
+ ),
36
41
):
37
42
if list_repos :
38
43
Repo ().list_repos ()
39
44
raise typer .Exit () # End, no further action
40
45
46
+ ctx .ensure_object (dict )
47
+ ctx .obj ["quiet" ] = quiet
48
+
41
49
if ctx .invoked_subcommand is None :
42
50
typer .echo (ctx .get_help ())
43
51
raise typer .Exit ()
44
52
45
53
54
+ @repo_remote .callback (invoke_without_command = True )
55
+ def remote (
56
+ ctx : typer .Context ,
57
+ repo_name : str = typer .Argument (None ),
58
+ all_repos : bool = typer .Option (
59
+ False , "--all-repos" , "-a" , help = "Show remotes of all repositories"
60
+ ),
61
+ ):
62
+ """
63
+ Show the git remotes for the specified repository.
64
+ If --all-repos is used, show remotes for all repositories.
65
+ """
66
+ repo = Repo ()
67
+ repo .ctx = ctx
68
+ repo .ctx .obj ["repo_name" ] = repo_name
69
+ repo_command (
70
+ all_repos ,
71
+ repo_name ,
72
+ all_msg = "Showing remotes for all repositories..." ,
73
+ missing_msg = "Please specify a repository name or use -a,--all-repos to show remotes of all repositories." ,
74
+ single_func = lambda repo_name : repo .get_repo_remote (repo_name ),
75
+ all_func = lambda repo_name : repo .get_repo_remote (repo_name ),
76
+ )
77
+
78
+
79
+ @repo_remote .command ("add" )
80
+ def remote_add (
81
+ ctx : typer .Context ,
82
+ remote_name : str = typer .Argument (..., help = "Name of the remote to add" ),
83
+ remote_url : str = typer .Argument (..., help = "URL of the remote to add" ),
84
+ ):
85
+ """
86
+ Add a git remote to the specified repository.
87
+ """
88
+ repo = Repo ()
89
+ repo .ctx = ctx
90
+ repo .remote_add (remote_name , remote_url )
91
+
92
+
93
+ @repo_remote .command ("remove" )
94
+ def remote_remove (
95
+ ctx : typer .Context ,
96
+ remote_name : str = typer .Argument (..., help = "Name of the remote to remove" ),
97
+ ):
98
+ """
99
+ Remove a git remote from the specified repository.
100
+ """
101
+ repo = Repo ()
102
+ repo .ctx = ctx
103
+ repo .remote_remove (remote_name )
104
+
105
+
46
106
@repo .command ()
47
107
def branch (
108
+ ctx : typer .Context ,
48
109
repo_name : str = typer .Argument (None ),
49
- branch_name : str = typer .Argument (None ),
110
+ branch_name : str = typer .Argument (None , help = "Branch name" ),
50
111
list_branches : bool = typer .Option (
51
112
False , "--list-branches" , "-l" , help = "List branches of the repository"
52
113
),
53
114
all_repos : bool = typer .Option (
54
115
False , "--all-repos" , "-a" , help = "Show branches of all repositories"
55
116
),
117
+ delete_branch : bool = typer .Option (
118
+ False , "--delete-branch" , "-d" , help = "Delete the specified branch"
119
+ ),
120
+ cloned_only : bool = typer .Option (
121
+ False , "--cloned-only" , "-c" , help = "Show branches only for cloned repositories"
122
+ ),
56
123
):
57
124
"""
58
125
Checkout or create a branch in a repository.
59
- If branch_name is provided, switch to that branch or create it if it doesn't exist.
60
126
If --all-repos is used, show branches for all repositories.
61
127
"""
62
128
repo = Repo ()
63
- if branch_name :
64
- repo .set_branch (branch_name )
65
-
66
- # else:
67
- # typer.echo(
68
- # typer.style(
69
- # "Create or set branch cannot be used with --all-repos.",
70
- # fg=typer.colors.RED,
71
- # )
72
- # )
73
- # return
74
-
129
+ repo .ctx = ctx
130
+ repo_list = repo .map
131
+ if delete_branch and branch_name :
132
+ repo .delete_branch (repo_name , branch_name )
133
+ raise typer .Exit ()
134
+ if cloned_only :
135
+ _ , fs_repos = repo ._list_repos ()
136
+ repo_list = sorted (fs_repos )
75
137
repo_command (
76
138
all_repos ,
77
139
repo_name ,
78
- all_msg = "Showing branches for all repositories..." ,
79
- missing_msg = "Please specify a repository name or use --all-repos to show branches of all repositories." ,
80
- single_func = lambda repo_name : repo .get_repo_branch (repo_name ),
81
- all_func = lambda repo_name : repo .get_repo_branch (repo_name ),
140
+ all_msg = None ,
141
+ missing_msg = "Please specify a repository name or use -a,--all-repos to show branches of all repositories." ,
142
+ single_func = lambda repo_name : repo .get_repo_branch (repo_name , branch_name ),
143
+ all_func = lambda repo_name : repo .get_repo_branch (repo_name , branch_name ),
144
+ repo_list = repo_list ,
145
+ )
146
+
147
+
148
+ @repo .command ()
149
+ def cd (
150
+ repo_name : str = typer .Argument (None ),
151
+ ):
152
+ """
153
+ Change directory to the specified repository.
154
+ """
155
+
156
+ repo_command (
157
+ False ,
158
+ repo_name ,
159
+ all_msg = None ,
160
+ missing_msg = "Please specify a repository name." ,
161
+ single_func = Repo ().cd_repo ,
162
+ all_func = Repo ().cd_repo ,
163
+ )
164
+
165
+
166
+ @repo .command ()
167
+ def checkout (
168
+ repo_name : str = typer .Argument (None ),
169
+ branch_name : str = typer .Argument (None , help = "Branch name to checkout" ),
170
+ ):
171
+ """
172
+ Checkout a branch in a repository.
173
+ """
174
+
175
+ def checkout_branch (name ):
176
+ Repo ().checkout_branch (repo_name , branch_name )
177
+
178
+ repo_command (
179
+ False ,
180
+ repo_name ,
181
+ all_msg = None ,
182
+ missing_msg = "Please specify a repository and branch name." ,
183
+ single_func = checkout_branch ,
184
+ all_func = checkout_branch ,
82
185
)
83
186
84
187
@@ -107,7 +210,7 @@ def clone_repo(name):
107
210
all_repos ,
108
211
repo_name ,
109
212
all_msg = "Cloning all repositories..." ,
110
- missing_msg = "Please specify a repository name or use --all-repos to clone all repositories." ,
213
+ missing_msg = "Please specify a repository name or use -a,- -all-repos to clone all repositories." ,
111
214
single_func = clone_repo ,
112
215
all_func = clone_repo ,
113
216
)
@@ -144,7 +247,7 @@ def do_commit(name):
144
247
145
248
146
249
@repo .command ()
147
- def delete (
250
+ def rm (
148
251
repo_name : str = typer .Argument (None ),
149
252
all_repos : bool = typer .Option (
150
253
False , "--all-repos" , "-a" , help = "Delete all repositories"
@@ -168,13 +271,34 @@ def do_delete(name):
168
271
all_repos ,
169
272
repo_name ,
170
273
all_msg = "Deleting all repositories..." ,
171
- missing_msg = "Please specify a repository name or use --all-repos to delete all repositories." ,
274
+ missing_msg = "Please specify a repository name or use -a,- -all-repos to delete all repositories." ,
172
275
single_func = do_delete ,
173
276
all_func = do_delete ,
174
277
fg = typer .colors .RED , # Red for delete
175
278
)
176
279
177
280
281
+ @repo .command ()
282
+ def diff (
283
+ repo_name : str = typer .Argument (None ),
284
+ all_repos : bool = typer .Option (
285
+ False , "--all-repos" , "-a" , help = "Show diffs of all repositories"
286
+ ),
287
+ ):
288
+ """
289
+ Show the git diff for the specified repository.
290
+ If --all-repos is used, show diffs for all repositories.
291
+ """
292
+ repo_command (
293
+ all_repos ,
294
+ repo_name ,
295
+ all_msg = "Showing diffs for all repositories..." ,
296
+ missing_msg = "Please specify a repository name or use -a,--all-repos to show diffs of all repositories." ,
297
+ single_func = lambda repo_name : Repo ().get_repo_diff (repo_name ),
298
+ all_func = lambda repo_name : Repo ().get_repo_diff (repo_name ),
299
+ )
300
+
301
+
178
302
@repo .command ()
179
303
def install (
180
304
repo_name : str = typer .Argument (None ),
@@ -190,7 +314,7 @@ def install(
190
314
all_repos ,
191
315
repo_name ,
192
316
all_msg = "Installing all repositories..." ,
193
- missing_msg = "Please specify a repository name or use --all-repos to install all repositories." ,
317
+ missing_msg = "Please specify a repository name or use -a,- -all-repos to install all repositories." ,
194
318
single_func = lambda repo_name : Package ().install_package (repo_name ),
195
319
all_func = lambda repo_name : Package ().install_package (repo_name ),
196
320
)
@@ -238,39 +362,6 @@ def open(
238
362
)
239
363
240
364
241
- @repo .command ()
242
- def origin (
243
- repo_name : str = typer .Argument (None ),
244
- repo_user : str = typer .Argument (None ),
245
- all_repos : bool = typer .Option (
246
- False , "--all-repos" , "-a" , help = "Show origin of all repositories"
247
- ),
248
- ):
249
- """
250
- Show or set the origin of a repository.
251
- """
252
- repo = Repo ()
253
- if repo_user and all_repos :
254
- typer .echo (
255
- typer .style (
256
- "Set origin cannot be used with --all-repos." ,
257
- fg = typer .colors .RED ,
258
- )
259
- )
260
- return
261
- if repo_user :
262
- repo .set_user (repo_user )
263
-
264
- repo_command (
265
- all_repos ,
266
- repo_name ,
267
- all_msg = "Showing origin for all repositories..." ,
268
- missing_msg = "Please specify a repository name or use --all-repos to show origins of all repositories." ,
269
- single_func = lambda name : repo .get_repo_origin (name ),
270
- all_func = lambda repo_name : repo .get_repo_origin (repo_name ),
271
- )
272
-
273
-
274
365
@repo .command ()
275
366
def patch (
276
367
repo_name : str = typer .Argument (None ),
@@ -327,14 +418,15 @@ def reset_repo(name):
327
418
all_repos ,
328
419
repo_name ,
329
420
all_msg = "Resetting all repositories..." ,
330
- missing_msg = "Please specify a repository name or use --all-repos to reset all repositories." ,
421
+ missing_msg = "Please specify a repository name or use -a,- -all-repos to reset all repositories." ,
331
422
single_func = reset_repo ,
332
423
all_func = reset_repo ,
333
424
)
334
425
335
426
336
427
@repo .command ()
337
428
def status (
429
+ ctx : typer .Context ,
338
430
repo_name : str = typer .Argument (None ),
339
431
all_repos : bool = typer .Option (
340
432
False , "--all-repos" , "-a" , help = "Show status of all repos"
@@ -345,18 +437,20 @@ def status(
345
437
If --all-repos is used, show the status for all repositories.
346
438
"""
347
439
repo = Repo ()
440
+ repo .ctx = ctx
348
441
repo_command (
349
442
all_repos ,
350
443
repo_name ,
351
444
all_msg = "Showing status for all repositories..." ,
352
- missing_msg = "Please specify a repository name or use --all-repos to show all repositories." ,
445
+ missing_msg = "Please specify a repository name or use -a,- -all-repos to show all repositories." ,
353
446
single_func = lambda repo_name : repo .get_repo_status (repo_name ),
354
447
all_func = lambda repo_name : repo .get_repo_status (repo_name ),
355
448
)
356
449
357
450
358
451
@repo .command ()
359
452
def sync (
453
+ ctx : typer .Context ,
360
454
repo_name : str = typer .Argument (None ),
361
455
all_repos : bool = typer .Option (
362
456
False , "--all-repos" , "-a" , help = "Sync all repositories"
@@ -367,6 +461,7 @@ def sync(
367
461
If --all-repos is used, sync all repositories.
368
462
"""
369
463
repo = Repo ()
464
+ repo .ctx = ctx
370
465
if not repo .map :
371
466
typer .echo (
372
467
typer .style (
@@ -380,14 +475,15 @@ def sync(
380
475
all_repos ,
381
476
repo_name ,
382
477
all_msg = "Syncing all repositories..." ,
383
- missing_msg = "Please specify a repository name or use --all-repos to sync all repositories." ,
478
+ missing_msg = "Please specify a repository name or use -a,- -all-repos to sync all repositories." ,
384
479
single_func = lambda repo_name : repo .sync_repo (repo_name ),
385
480
all_func = lambda repo_name : repo .sync_repo (repo_name ),
386
481
)
387
482
388
483
389
484
@repo .command ()
390
485
def test (
486
+ ctx : typer .Context ,
391
487
repo_name : str = typer .Argument (None ),
392
488
modules : list [str ] = typer .Argument (None ),
393
489
keep_db : bool = typer .Option (
@@ -414,6 +510,7 @@ def test(
414
510
If --setenv is used, set the DJANGO_SETTINGS_MODULE environment variable.
415
511
"""
416
512
test_runner = Test ()
513
+ test_runner .ctx = ctx
417
514
if modules :
418
515
test_runner .set_modules (modules )
419
516
if keep_db :
0 commit comments