Skip to content

Commit ad46978

Browse files
committed
Fix version visualization and add verbose logging
Raise an exception for unparsable versions and aggregate visualization output in a list before printing. Add a verbose logging option to the `show_bump` command for detailed logging control.
1 parent 5a64ae0 commit ad46978

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

bumpversion/cli.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,17 @@ def sample_config(prompt: bool, destination: str) -> None:
575575
help="Config file to read most of the variables from.",
576576
)
577577
@click.option("--ascii", is_flag=True, help="Use ASCII characters only.")
578-
def show_bump(version: str, config_file: Optional[str], ascii: bool) -> None:
578+
@click.option(
579+
"-v",
580+
"--verbose",
581+
count=True,
582+
required=False,
583+
envvar="BUMPVERSION_VERBOSE",
584+
help="Print verbose logging to stderr. Can specify several times for more verbosity.",
585+
)
586+
def show_bump(version: str, config_file: Optional[str], ascii: bool, verbose: int) -> None:
579587
"""Show the possible versions resulting from the bump subcommand."""
588+
setup_logging(verbose)
580589
found_config_file = find_config_file(config_file)
581590
config = get_configuration(found_config_file)
582591
if not version:

bumpversion/visualize.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def filter_version_parts(config: Config) -> List[str]:
111111
def visualize(config: Config, version_str: str, box_style: str = "light") -> None:
112112
"""Output a visualization of the bump-my-version bump process."""
113113
version = config.version_config.parse(version_str)
114+
if version is None:
115+
raise BumpVersionError(f"Unable to parse version {version_str}")
114116
version_parts = filter_version_parts(config)
115117
num_parts = len(version_parts)
116118

@@ -120,7 +122,7 @@ def visualize(config: Config, version_str: str, box_style: str = "light") -> Non
120122
version_lead = lead_string(version_str, border)
121123
blank_lead = lead_string(version_str, border, blank=True)
122124
version_part_length = max(len(part) for part in version_parts)
123-
125+
lines = []
124126
for i, part in enumerate(version_parts):
125127
line = [version_lead] if i == 0 else [blank_lead]
126128

@@ -135,4 +137,5 @@ def visualize(config: Config, version_str: str, box_style: str = "light") -> Non
135137
line.append(connection_str(border, has_next=has_next, has_previous=has_previous))
136138
line.append(labeled_line(part, border, version_part_length))
137139
line.append(next_version_str)
138-
print_info("".join(line))
140+
lines.append("".join(line))
141+
print_info("\n".join(lines))

0 commit comments

Comments
 (0)