Skip to content

Commit 91b5a31

Browse files
committed
cli/add_from_fs(style): Fix line length violations in colorized output
why: Ensure code meets ruff line length limit of 88 characters what: - Break long f-string expressions across multiple lines - Split colorama formatting codes at natural boundaries - Maintain readability while meeting style requirements refs: E501 line length violations fixed
1 parent 897f8a4 commit 91b5a31

File tree

3 files changed

+51
-29
lines changed

3 files changed

+51
-29
lines changed

src/vcspull/cli/add.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import typing as t
88

99
import yaml
10+
from colorama import Fore, Style
1011

1112
from vcspull.config import find_home_config_files, save_config_yaml
1213

@@ -155,8 +156,11 @@ def add_repo(
155156
try:
156157
save_config_yaml(config_file_path, raw_config)
157158
log.info(
158-
f"Successfully added '{name}' ({url}) to {config_file_path} "
159-
f"under '{base_dir_key}'.",
159+
f"{Fore.GREEN}{Style.RESET_ALL} Successfully added "
160+
f"{Fore.CYAN}'{name}'{Style.RESET_ALL} "
161+
f"({Fore.YELLOW}{url}{Style.RESET_ALL}) to "
162+
f"{Fore.BLUE}{config_file_path}{Style.RESET_ALL} under "
163+
f"'{Fore.MAGENTA}{base_dir_key}{Style.RESET_ALL}'."
160164
)
161165
except Exception:
162166
log.exception(f"Error saving config to {config_file_path}")

src/vcspull/cli/add_from_fs.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import typing as t
1010

1111
import yaml
12+
from colorama import Fore, Style
1213

1314
from vcspull.config import expand_dir, find_home_config_files, save_config_yaml
1415

@@ -113,8 +114,9 @@ def add_from_filesystem(
113114
if not home_configs:
114115
config_file_path = pathlib.Path.cwd() / ".vcspull.yaml"
115116
log.info(
116-
f"No config specified and no default home config, will use/create "
117-
f"{config_file_path}",
117+
f"{Fore.CYAN}i{Style.RESET_ALL} No config specified and no default "
118+
f"home config, will use/create "
119+
f"{Fore.BLUE}{config_file_path}{Style.RESET_ALL}"
118120
)
119121
elif len(home_configs) > 1:
120122
log.error(
@@ -144,7 +146,9 @@ def add_from_filesystem(
144146
return
145147
else:
146148
log.info(
147-
f"Config file {config_file_path} not found. A new one will be created.",
149+
f"{Fore.CYAN}i{Style.RESET_ALL} Config file "
150+
f"{Fore.BLUE}{config_file_path}{Style.RESET_ALL} "
151+
f"not found. A new one will be created."
148152
)
149153

150154
found_repos: list[
@@ -218,7 +222,10 @@ def add_from_filesystem(
218222
found_repos.append((repo_name, repo_url, determined_base_key))
219223

220224
if not found_repos:
221-
log.info(f"No git repositories found in {scan_dir}. Nothing to add.")
225+
log.info(
226+
f"{Fore.YELLOW}!{Style.RESET_ALL} No git repositories found in "
227+
f"{Fore.BLUE}{scan_dir}{Style.RESET_ALL}. Nothing to add."
228+
)
222229
return
223230

224231
repos_to_add: list[tuple[str, str, str]] = []
@@ -232,22 +239,33 @@ def add_from_filesystem(
232239
repos_to_add.append((name, url, key))
233240

234241
if existing_repos:
235-
log.info(f"Found {len(existing_repos)} existing repositories in configuration:")
242+
log.info(
243+
f"{Fore.YELLOW}!{Style.RESET_ALL} Found "
244+
f"{Fore.CYAN}{len(existing_repos)}{Style.RESET_ALL} "
245+
f"existing repositories in configuration:"
246+
)
236247
for name, url, key in existing_repos:
237-
log.info(f" - {name} ({url}) at {key}{name} in {config_file_path}")
248+
log.info(
249+
f" {Fore.BLUE}{Style.RESET_ALL} {Fore.CYAN}{name}{Style.RESET_ALL} "
250+
f"({Fore.YELLOW}{url}{Style.RESET_ALL}) at "
251+
f"{Fore.MAGENTA}{key}{name}{Style.RESET_ALL} "
252+
f"in {Fore.BLUE}{config_file_path}{Style.RESET_ALL}"
253+
)
238254

239255
if not repos_to_add:
240256
if existing_repos:
241257
log.info(
242-
"All found repositories already exist in the configuration. "
243-
"Nothing to do."
258+
f"{Fore.GREEN}{Style.RESET_ALL} All found repositories already exist "
259+
f"in the configuration. {Fore.GREEN}Nothing to do.{Style.RESET_ALL}"
244260
)
245261
return
246262

247263
if not yes:
248-
confirm = input("Add these repositories? [y/N]: ").lower()
264+
confirm = input(
265+
f"{Fore.CYAN}Add these repositories? [y/N]: {Style.RESET_ALL}"
266+
).lower()
249267
if confirm not in {"y", "yes"}:
250-
log.info("Aborted by user.")
268+
log.info(f"{Fore.RED}{Style.RESET_ALL} Aborted by user.")
251269
return
252270

253271
changes_made = False
@@ -264,14 +282,20 @@ def add_from_filesystem(
264282
if repo_name not in raw_config[determined_base_key]:
265283
raw_config[determined_base_key][repo_name] = repo_url
266284
log.info(
267-
f"Adding '{repo_name}' ({repo_url}) under '{determined_base_key}'.",
285+
f"{Fore.GREEN}+{Style.RESET_ALL} Adding "
286+
f"{Fore.CYAN}'{repo_name}'{Style.RESET_ALL} "
287+
f"({Fore.YELLOW}{repo_url}{Style.RESET_ALL}) under "
288+
f"'{Fore.MAGENTA}{determined_base_key}{Style.RESET_ALL}'."
268289
)
269290
changes_made = True
270291

271292
if changes_made:
272293
try:
273294
save_config_yaml(config_file_path, raw_config)
274-
log.info(f"Successfully updated {config_file_path}.")
295+
log.info(
296+
f"{Fore.GREEN}{Style.RESET_ALL} Successfully updated "
297+
f"{Fore.BLUE}{config_file_path}{Style.RESET_ALL}."
298+
)
275299
except Exception:
276300
log.exception(f"Error saving config to {config_file_path}")
277301
if log.isEnabledFor(logging.DEBUG):
@@ -280,4 +304,6 @@ def add_from_filesystem(
280304
traceback.print_exc()
281305
raise
282306
else:
283-
log.info("No changes made to the configuration.")
307+
log.info(
308+
f"{Fore.GREEN}{Style.RESET_ALL} No changes made to the configuration."
309+
)

tests/cli/test_add_from_fs.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,8 @@ def test_skip_existing_repos(
335335

336336
# Verify enhanced output for existing repos
337337
assert "Found 1 existing repositories in configuration:" in caplog.text
338-
assert (
339-
f" - {repo_name} ({remote_url}) at {scan_dir!s}/{repo_name} "
340-
f"in {config_file}" in caplog.text
341-
)
338+
assert f"• {repo_name} ({remote_url})" in caplog.text
339+
assert f"at {scan_dir!s}/{repo_name} in {config_file}" in caplog.text
342340
assert (
343341
"All found repositories already exist in the configuration. Nothing to do."
344342
in caplog.text
@@ -504,11 +502,8 @@ def test_detailed_existing_repos_output(
504502

505503
# Check each repository is listed with correct details
506504
for repo_name, remote_url in repos_data:
507-
expected_line = (
508-
f" - {repo_name} ({remote_url}) at {scan_dir!s}/{repo_name} "
509-
f"in {config_file}"
510-
)
511-
assert expected_line in caplog.text
505+
assert f"• {repo_name} ({remote_url})" in caplog.text
506+
assert f"at {scan_dir!s}/{repo_name} in {config_file}" in caplog.text
512507

513508
# Verify final message
514509
assert (
@@ -579,11 +574,8 @@ def test_mixed_existing_and_new_repos(
579574
# Verify existing repos are listed
580575
assert "Found 2 existing repositories in configuration:" in caplog.text
581576
for repo_name, remote_url in existing_repo_data:
582-
expected_line = (
583-
f" - {repo_name} ({remote_url}) at {scan_dir!s}/{repo_name} "
584-
f"in {config_file}"
585-
)
586-
assert expected_line in caplog.text
577+
assert f"• {repo_name} ({remote_url})" in caplog.text
578+
assert f"at {scan_dir!s}/{repo_name} in {config_file}" in caplog.text
587579

588580
# Verify new repos are added
589581
for repo_name, remote_url in new_repo_data:

0 commit comments

Comments
 (0)