Skip to content

Commit

Permalink
Fix version visualization and add verbose logging
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
coordt committed Aug 13, 2024
1 parent 5a64ae0 commit ad46978
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 10 additions & 1 deletion bumpversion/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,17 @@ def sample_config(prompt: bool, destination: str) -> None:
help="Config file to read most of the variables from.",
)
@click.option("--ascii", is_flag=True, help="Use ASCII characters only.")
def show_bump(version: str, config_file: Optional[str], ascii: bool) -> None:
@click.option(
"-v",
"--verbose",
count=True,
required=False,
envvar="BUMPVERSION_VERBOSE",
help="Print verbose logging to stderr. Can specify several times for more verbosity.",
)
def show_bump(version: str, config_file: Optional[str], ascii: bool, verbose: int) -> None:
"""Show the possible versions resulting from the bump subcommand."""
setup_logging(verbose)
found_config_file = find_config_file(config_file)
config = get_configuration(found_config_file)
if not version:
Expand Down
7 changes: 5 additions & 2 deletions bumpversion/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def filter_version_parts(config: Config) -> List[str]:
def visualize(config: Config, version_str: str, box_style: str = "light") -> None:
"""Output a visualization of the bump-my-version bump process."""
version = config.version_config.parse(version_str)
if version is None:
raise BumpVersionError(f"Unable to parse version {version_str}")
version_parts = filter_version_parts(config)
num_parts = len(version_parts)

Expand All @@ -120,7 +122,7 @@ def visualize(config: Config, version_str: str, box_style: str = "light") -> Non
version_lead = lead_string(version_str, border)
blank_lead = lead_string(version_str, border, blank=True)
version_part_length = max(len(part) for part in version_parts)

lines = []
for i, part in enumerate(version_parts):
line = [version_lead] if i == 0 else [blank_lead]

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

0 comments on commit ad46978

Please sign in to comment.