Skip to content

Commit

Permalink
Made VERSION_PART optional.
Browse files Browse the repository at this point in the history
- Fixes #16
- `VERSION_PART` is detected from the arguments based on the configuration
  • Loading branch information
coordt committed Jun 12, 2023
1 parent d78ff46 commit f236b7d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
27 changes: 19 additions & 8 deletions bumpversion/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@

@click.command(context_settings={"ignore_unknown_options": True})
@click.version_option(version=__version__)
@click.argument("version_part")
@click.argument("files", nargs=-1, type=click.Path())
@click.argument("args", nargs=-1, type=str)
@click.option(
"--config-file",
metavar="FILE",
Expand Down Expand Up @@ -165,8 +164,8 @@
help="List machine readable information",
)
def cli(
version_part: str,
files: list,
# version_part: str,
args: list,
config_file: Optional[str],
verbose: int,
allow_dirty: Optional[bool],
Expand All @@ -190,6 +189,8 @@ def cli(
"""
Change the version.
ARGS may contain any of the following:
VERSION_PART is the part of the version to increase, e.g. `minor` .
Valid values include those given in the `--serialize` / `--parse` option.
Expand Down Expand Up @@ -219,6 +220,14 @@ def cli(

found_config_file = find_config_file(config_file)
config = get_configuration(found_config_file, **overrides)
if args:
if args[0] not in config.parts.keys():
raise ValueError(f"Unknown version part: {args[0]}")
version_part = args[0]
files = args[1:]
else:
version_part = None
files = args

if show_list:
log_list(config, version_part, new_version)
Expand All @@ -240,10 +249,12 @@ def cli(
def log_list(config: Config, version_part: Optional[str], new_version: Optional[str]) -> None:
"""Output configuration with new version."""
ctx = get_context(config)
version = config.version_config.parse(config.current_version)
next_version = get_next_version(version, config, version_part, new_version)
next_version_str = config.version_config.serialize(next_version, ctx)
if version_part:
version = config.version_config.parse(config.current_version)
next_version = get_next_version(version, config, version_part, new_version)
next_version_str = config.version_config.serialize(next_version, ctx)

click.echo(f"new_version={next_version_str}")

click.echo(f"new_version={next_version_str}")
for key, value in config.dict(exclude={"scm_info", "parts"}).items():
click.echo(f"{key}={value}")
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ def test_cli_options_override_config(tmp_path: Path, fixtures_path: Path, mocker
"my-replace",
"--no-commit",
"--no-tag",
"patch",
"slurp",
"do-this-file.txt",
],
)

# Assert
assert result.exit_code == 0
assert mocked_do_bump.call_count == 1
assert mocked_do_bump.call_args[0][0] == "patch"
assert mocked_do_bump.call_args[0][0] == "slurp"
assert mocked_do_bump.call_args[0][1] == "1.2.0"
the_config = mocked_do_bump.call_args[0][2]
assert the_config.current_version == "1.1.0"
Expand Down

0 comments on commit f236b7d

Please sign in to comment.