Skip to content

Commit f236b7d

Browse files
committed
Made VERSION_PART optional.
- Fixes #16 - `VERSION_PART` is detected from the arguments based on the configuration
1 parent d78ff46 commit f236b7d

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

bumpversion/cli.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727

2828
@click.command(context_settings={"ignore_unknown_options": True})
2929
@click.version_option(version=__version__)
30-
@click.argument("version_part")
31-
@click.argument("files", nargs=-1, type=click.Path())
30+
@click.argument("args", nargs=-1, type=str)
3231
@click.option(
3332
"--config-file",
3433
metavar="FILE",
@@ -165,8 +164,8 @@
165164
help="List machine readable information",
166165
)
167166
def cli(
168-
version_part: str,
169-
files: list,
167+
# version_part: str,
168+
args: list,
170169
config_file: Optional[str],
171170
verbose: int,
172171
allow_dirty: Optional[bool],
@@ -190,6 +189,8 @@ def cli(
190189
"""
191190
Change the version.
192191
192+
ARGS may contain any of the following:
193+
193194
VERSION_PART is the part of the version to increase, e.g. `minor` .
194195
Valid values include those given in the `--serialize` / `--parse` option.
195196
@@ -219,6 +220,14 @@ def cli(
219220

220221
found_config_file = find_config_file(config_file)
221222
config = get_configuration(found_config_file, **overrides)
223+
if args:
224+
if args[0] not in config.parts.keys():
225+
raise ValueError(f"Unknown version part: {args[0]}")
226+
version_part = args[0]
227+
files = args[1:]
228+
else:
229+
version_part = None
230+
files = args
222231

223232
if show_list:
224233
log_list(config, version_part, new_version)
@@ -240,10 +249,12 @@ def cli(
240249
def log_list(config: Config, version_part: Optional[str], new_version: Optional[str]) -> None:
241250
"""Output configuration with new version."""
242251
ctx = get_context(config)
243-
version = config.version_config.parse(config.current_version)
244-
next_version = get_next_version(version, config, version_part, new_version)
245-
next_version_str = config.version_config.serialize(next_version, ctx)
252+
if version_part:
253+
version = config.version_config.parse(config.current_version)
254+
next_version = get_next_version(version, config, version_part, new_version)
255+
next_version_str = config.version_config.serialize(next_version, ctx)
256+
257+
click.echo(f"new_version={next_version_str}")
246258

247-
click.echo(f"new_version={next_version_str}")
248259
for key, value in config.dict(exclude={"scm_info", "parts"}).items():
249260
click.echo(f"{key}={value}")

tests/test_cli.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ def test_cli_options_override_config(tmp_path: Path, fixtures_path: Path, mocker
101101
"my-replace",
102102
"--no-commit",
103103
"--no-tag",
104-
"patch",
104+
"slurp",
105105
"do-this-file.txt",
106106
],
107107
)
108108

109109
# Assert
110110
assert result.exit_code == 0
111111
assert mocked_do_bump.call_count == 1
112-
assert mocked_do_bump.call_args[0][0] == "patch"
112+
assert mocked_do_bump.call_args[0][0] == "slurp"
113113
assert mocked_do_bump.call_args[0][1] == "1.2.0"
114114
the_config = mocked_do_bump.call_args[0][2]
115115
assert the_config.current_version == "1.1.0"

0 commit comments

Comments
 (0)