11import argparse
22import logging
33import sys
4+ import typing as t
45from copy import deepcopy
56
6- import click
7- import click .shell_completion
8- from click .shell_completion import CompletionItem
9-
107from libvcs ._internal .shortcuts import create_project
118from libvcs .url import registry as url_tools
12- from vcspull .types import ConfigDict
139
1410from ..config import filter_repos , find_config_files , load_configs
1511
1612log = logging .getLogger (__name__ )
1713
1814
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-
5915def clamp (n , _min , _max ):
6016 return max (_min , min (n , _max ))
6117
@@ -64,29 +20,6 @@ def clamp(n, _min, _max):
6420NO_REPOS_FOR_TERM_MSG = 'No repo found in config(s) for "{name}"'
6521
6622
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-
9023def create_sync_subparser (parser : argparse .ArgumentParser ) -> argparse .ArgumentParser :
9124 parser .add_argument ("--config" , "-c" , help = "Specify config" )
9225 parser .add_argument ("repo_terms" , nargs = "+" , help = "Specify config" )
@@ -104,7 +37,9 @@ def sync(
10437 repo_terms ,
10538 config ,
10639 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
10843) -> None :
10944 if config :
11045 configs = load_configs ([config ])
0 commit comments