@@ -91,52 +91,58 @@ def create_sync_subparser(parser: argparse.ArgumentParser) -> argparse.ArgumentP
91
91
parser .add_argument ("--config" , "-c" , help = "Specify config" )
92
92
parser .add_argument ("repo_terms" , nargs = "+" , help = "Specify config" )
93
93
parser .add_argument (
94
- "--exit-on_error" , "-x" , dest = "exit_on_error" , help = "Specify config"
94
+ "--exit-on-error" ,
95
+ "-x" ,
96
+ action = "store_true" ,
97
+ dest = "exit_on_error" ,
98
+ help = "Specify config" ,
95
99
)
96
100
return parser
97
101
98
102
99
- def sync (repo_terms , config , exit_on_error : bool ) -> None :
103
+ def sync (
104
+ repo_terms ,
105
+ config ,
106
+ exit_on_error : bool ,
107
+ parser : argparse .ArgumentParser | None = None ,
108
+ ) -> None :
100
109
if config :
101
110
configs = load_configs ([config ])
102
111
else :
103
112
configs = load_configs (find_config_files (include_home = True ))
104
113
found_repos = []
105
114
106
- if repo_terms :
107
- for repo_term in repo_terms :
108
- dir , vcs_url , name = None , None , None
109
- if any (repo_term .startswith (n ) for n in ["./" , "/" , "~" , "$HOME" ]):
110
- dir = repo_term
111
- elif any (repo_term .startswith (n ) for n in ["http" , "git" , "svn" , "hg" ]):
112
- vcs_url = repo_term
113
- else :
114
- name = repo_term
115
-
116
- # collect the repos from the config files
117
- found = filter_repos (configs , dir = dir , vcs_url = vcs_url , name = name )
118
- if len (found ) == 0 :
119
- click .echo (NO_REPOS_FOR_TERM_MSG .format (name = name ))
120
- found_repos .extend (
121
- filter_repos (configs , dir = dir , vcs_url = vcs_url , name = name )
122
- )
123
- else :
124
- click .echo (ctx .get_help (), color = ctx .color )
125
- ctx .exit ()
115
+ for repo_term in repo_terms :
116
+ dir , vcs_url , name = None , None , None
117
+ if any (repo_term .startswith (n ) for n in ["./" , "/" , "~" , "$HOME" ]):
118
+ dir = repo_term
119
+ elif any (repo_term .startswith (n ) for n in ["http" , "git" , "svn" , "hg" ]):
120
+ vcs_url = repo_term
121
+ else :
122
+ name = repo_term
123
+
124
+ # collect the repos from the config files
125
+ found = filter_repos (configs , dir = dir , vcs_url = vcs_url , name = name )
126
+ if len (found ) == 0 :
127
+ print (NO_REPOS_FOR_TERM_MSG .format (name = name ))
128
+ found_repos .extend (filter_repos (configs , dir = dir , vcs_url = vcs_url , name = name ))
126
129
127
130
for repo in found_repos :
128
131
try :
129
132
update_repo (repo )
130
133
except Exception :
131
- click . echo (
134
+ print (
132
135
f'Failed syncing { repo .get ("name" )} ' ,
133
136
)
134
137
if log .isEnabledFor (logging .DEBUG ):
135
138
import traceback
136
139
137
140
traceback .print_exc ()
138
141
if exit_on_error :
139
- raise click .ClickException (EXIT_ON_ERROR_MSG )
142
+ if parser is not None :
143
+ parser .exit (status = 1 , message = EXIT_ON_ERROR_MSG )
144
+ else :
145
+ raise SystemExit (EXIT_ON_ERROR_MSG )
140
146
141
147
142
148
def progress_cb (output , timestamp ):
0 commit comments