1
1
import argparse
2
2
import logging
3
3
import sys
4
+ import typing as t
4
5
from copy import deepcopy
5
6
6
- import click
7
- import click .shell_completion
8
- from click .shell_completion import CompletionItem
9
-
10
7
from libvcs ._internal .shortcuts import create_project
11
8
from libvcs .url import registry as url_tools
12
- from vcspull .types import ConfigDict
13
9
14
10
from ..config import filter_repos , find_config_files , load_configs
15
11
16
12
log = logging .getLogger (__name__ )
17
13
18
14
19
- def get_repo_completions (
20
- ctx : click .Context , param : click .Parameter , incomplete : str
21
- ) -> list [CompletionItem ]:
22
- configs = (
23
- load_configs (find_config_files (include_home = True ))
24
- if ctx .params ["config" ] is None
25
- else load_configs (files = [ctx .params ["config" ]])
26
- )
27
- found_repos : list [ConfigDict ] = []
28
- repo_terms = [incomplete ]
29
-
30
- for repo_term in repo_terms :
31
- dir , vcs_url , name = None , None , None
32
- if any (repo_term .startswith (n ) for n in ["./" , "/" , "~" , "$HOME" ]):
33
- dir = dir
34
- elif any (repo_term .startswith (n ) for n in ["http" , "git" , "svn" , "hg" ]):
35
- vcs_url = repo_term
36
- else :
37
- name = repo_term
38
-
39
- # collect the repos from the config files
40
- found_repos .extend (filter_repos (configs , dir = dir , vcs_url = vcs_url , name = name ))
41
- if len (found_repos ) == 0 :
42
- found_repos = configs
43
-
44
- return [
45
- CompletionItem (o ["name" ])
46
- for o in found_repos
47
- if o ["name" ].startswith (incomplete )
48
- ]
49
-
50
-
51
- def get_config_file_completions (ctx , args , incomplete ):
52
- return [
53
- click .shell_completion .CompletionItem (c )
54
- for c in find_config_files (include_home = True )
55
- if str (c ).startswith (incomplete )
56
- ]
57
-
58
-
59
15
def clamp (n , _min , _max ):
60
16
return max (_min , min (n , _max ))
61
17
@@ -64,29 +20,6 @@ def clamp(n, _min, _max):
64
20
NO_REPOS_FOR_TERM_MSG = 'No repo found in config(s) for "{name}"'
65
21
66
22
67
- # @click.command(name="sync")
68
- # @click.pass_context
69
- # @click.argument(
70
- # "repo_terms", type=click.STRING, nargs=-1, shell_complete=get_repo_completions
71
- # )
72
- # @click.option(
73
- # "config",
74
- # "--config",
75
- # "-c",
76
- # type=click.Path(exists=True),
77
- # help="Specify config",
78
- # shell_complete=get_config_file_completions,
79
- # )
80
- # @click.option(
81
- # "exit_on_error",
82
- # "--exit-on-error",
83
- # "-x",
84
- # is_flag=True,
85
- # default=False,
86
- # help="Exit immediately when encountering an error syncing multiple repos",
87
- # )
88
-
89
-
90
23
def create_sync_subparser (parser : argparse .ArgumentParser ) -> argparse .ArgumentParser :
91
24
parser .add_argument ("--config" , "-c" , help = "Specify config" )
92
25
parser .add_argument ("repo_terms" , nargs = "+" , help = "Specify config" )
@@ -104,7 +37,9 @@ def sync(
104
37
repo_terms ,
105
38
config ,
106
39
exit_on_error : bool ,
107
- parser : argparse .ArgumentParser | None = None ,
40
+ parser : t .Optional [
41
+ argparse .ArgumentParser
42
+ ] = None , # optional so sync can be unit tested
108
43
) -> None :
109
44
if config :
110
45
configs = load_configs ([config ])
0 commit comments