Skip to content

Commit 098189c

Browse files
committed
squash more
1 parent b3e3473 commit 098189c

File tree

3 files changed

+140
-124
lines changed

3 files changed

+140
-124
lines changed

src/vcspull/cli/__init__.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,51 +20,36 @@ def create_parser():
2020
parser = argparse.ArgumentParser(prog="vcspull")
2121
parser.add_argument(
2222
"--version",
23+
"-V",
2324
action="version",
2425
version=f"%(prog)s {__version__}, libvcs {libvcs_version}",
2526
)
26-
parser.add_argument("--log-level", action="store", default="INFO")
27+
parser.add_argument(
28+
"--log-level",
29+
action="store",
30+
default="INFO",
31+
help="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
32+
)
2733
subparsers = parser.add_subparsers(dest="subparser_name")
2834
sync_parser = subparsers.add_parser("sync")
2935
create_sync_subparser(sync_parser)
3036

3137
return parser
3238

3339

34-
# @click.group(
35-
# context_settings={
36-
# "obj": {},
37-
# "help_option_names": ["-h", "--help"],
38-
# }
39-
# )
40-
# @click.option(
41-
# "--log-level",
42-
# default="INFO",
43-
# help="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
44-
# )
45-
# @click.version_option(
46-
# __version__,
47-
# "-V",
48-
# "--version",
49-
# message=f"%(prog)s %(version)s, libvcs {libvcs_version}",
50-
# )
5140
def cli(args=None):
5241
parser = create_parser()
5342
args = parser.parse_args(args)
5443

5544
setup_logger(log=log, level=args.log_level.upper())
5645

57-
print(f"args: {args}")
58-
print(f"args: {args.__dict__}")
5946
if args.subparser_name is None:
6047
parser.print_help()
48+
return
6149
elif args.subparser_name == "sync":
6250
sync(
6351
repo_terms=args.repo_terms,
6452
config=args.config,
6553
exit_on_error=args.exit_on_error,
54+
parser=parser,
6655
)
67-
68-
69-
# # Register sub-commands here
70-
# cli.add_command(sync)

src/vcspull/cli/sync.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,52 +91,58 @@ def create_sync_subparser(parser: argparse.ArgumentParser) -> argparse.ArgumentP
9191
parser.add_argument("--config", "-c", help="Specify config")
9292
parser.add_argument("repo_terms", nargs="+", help="Specify config")
9393
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",
9599
)
96100
return parser
97101

98102

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:
100109
if config:
101110
configs = load_configs([config])
102111
else:
103112
configs = load_configs(find_config_files(include_home=True))
104113
found_repos = []
105114

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))
126129

127130
for repo in found_repos:
128131
try:
129132
update_repo(repo)
130133
except Exception:
131-
click.echo(
134+
print(
132135
f'Failed syncing {repo.get("name")}',
133136
)
134137
if log.isEnabledFor(logging.DEBUG):
135138
import traceback
136139

137140
traceback.print_exc()
138141
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)
140146

141147

142148
def progress_cb(output, timestamp):

0 commit comments

Comments
 (0)