Skip to content

Commit b01fffc

Browse files
committed
Adds --increment option to show subcommand
- when specified it increments the current version and adds `new_version` to the available output.
1 parent 9bce887 commit b01fffc

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

bumpversion/cli.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,20 @@ def bump(
272272
default="default",
273273
help="Config file to read most of the variables from.",
274274
)
275-
def show(args: List[str], config_file: Optional[str], format_: str) -> None:
275+
@click.option(
276+
"-i",
277+
"--increment",
278+
required=False,
279+
envvar="BUMPVERSION_INCREMENT",
280+
type=str,
281+
help="Increment the version part and add `new_version` to the configuration.",
282+
)
283+
def show(args: List[str], config_file: Optional[str], format_: str, increment: Optional[str]) -> None:
276284
"""Show current configuration information."""
277285
found_config_file = find_config_file(config_file)
278286
config = get_configuration(found_config_file)
279287

280288
if not args:
281-
do_show("all", config=config, format_=format_)
289+
do_show("all", config=config, format_=format_, increment=increment)
282290
else:
283-
do_show(*args, config=config, format_=format_)
291+
do_show(*args, config=config, format_=format_, increment=increment)

bumpversion/show.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,16 @@ def log_list(config: Config, version_part: Optional[str], new_version: Optional[
121121
print_info(f"{key}={value}")
122122

123123

124-
def do_show(*args, config: Config, format_: str = "default") -> None:
124+
def do_show(*args, config: Config, format_: str = "default", increment: Optional[str] = None) -> None:
125125
"""Show current version or configuration information."""
126126
config_dict = config.dict()
127+
ctx = get_context(config)
128+
129+
if increment:
130+
version = config.version_config.parse(config.current_version)
131+
next_version = get_next_version(version, config, increment, None)
132+
next_version_str = config.version_config.serialize(next_version, ctx)
133+
config_dict["new_version"] = next_version_str
127134

128135
try:
129136
if "all" in args or not args:

tests/test_cli.py

+19
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,25 @@ def test_show(tmp_path: Path, fixtures_path: Path):
298298
assert result.output.splitlines(keepends=False) == ["1.0.0"]
299299

300300

301+
def test_show_and_increment(tmp_path: Path, fixtures_path: Path):
302+
"""The show subcommand should incrment the version and display it."""
303+
# Arrange
304+
config_path = tmp_path / "pyproject.toml"
305+
toml_path = fixtures_path / "basic_cfg.toml"
306+
shutil.copy(toml_path, config_path)
307+
runner: CliRunner = CliRunner()
308+
309+
with inside_dir(tmp_path):
310+
result: Result = runner.invoke(cli.cli, ["show", "new_version", "--increment", "minor"])
311+
312+
if result.exit_code != 0:
313+
print(result.output)
314+
print(result.exception)
315+
316+
assert result.exit_code == 0
317+
assert result.output.splitlines(keepends=False) == ["1.1.0-dev"]
318+
319+
301320
def test_show_no_args(tmp_path: Path, fixtures_path: Path):
302321
"""The show subcommand should list the entire configuration."""
303322
# Arrange

tests/test_show.py

+12
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,15 @@ def test_do_show(
156156
show.do_show(config=conf, format_=format_, *req_args)
157157
captured = capsys.readouterr()
158158
assert captured.out.strip() == expected
159+
160+
161+
def test_do_show_increment(tmp_path: Path, fixtures_path: Path, capsys: pytest.CaptureFixture) -> None:
162+
"""Test the show method with increment."""
163+
config_path = tmp_path / "pyproject.toml"
164+
toml_path = fixtures_path / "basic_cfg.toml"
165+
shutil.copy(toml_path, config_path)
166+
with inside_dir(tmp_path):
167+
conf = config.get_configuration(config_file=fixtures_path.joinpath(config_path))
168+
show.do_show("current_version", "new_version", config=conf, format_="default", increment="minor")
169+
captured = capsys.readouterr()
170+
assert captured.out.strip() == "{'current_version': '1.0.0', 'new_version': '1.1.0-dev'}"

0 commit comments

Comments
 (0)