From 9d965e57f2c0a41476d75ec053653416eae966c9 Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Thu, 22 Jun 2023 13:38:24 -0500 Subject: [PATCH] Fixed `--help` and `bump` invocations - `--help` works for individual sub-commands, but not for the command - `bump` now works and fixed tests --- CHANGELOG.md | 31 +++++++++++++++++++++++++++++++ bumpversion/__init__.py | 2 +- bumpversion/aliases.py | 3 +++ bumpversion/cli.py | 1 + pyproject.toml | 2 +- tests/test_cli.py | 39 ++++++++++++++++++++++++++++++++------- 6 files changed, 69 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1a1f92c..491a7feb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,36 @@ # Changelog +## Unreleased (2023-06-21) +[Compare the full difference.](https://github.com/callowayproject/bump-my-version/compare/0.5.1...HEAD) + +### Fixes + +- Fixed issue regarding TOML types. [8960d24](https://github.com/callowayproject/bump-my-version/commit/8960d249183cf78d8b35967b86fef8701fc9c37e) + + - `tomlkit.parse()` returns a `TOMLDocument`. + - `unwrap()` converts it into a `dict` +### New + +- Added documentation for the show command. [d537274](https://github.com/callowayproject/bump-my-version/commit/d5372742a8cf76777f1bf4450bf31e9310d04681) + +- Adds `--increment` option to `show` subcommand. [b01fffc](https://github.com/callowayproject/bump-my-version/commit/b01fffcad8479db25375d53fdeebc879d7317b11) + + - when specified it increments the current version and adds `new_version` to the available output. +- Added `show` subcommand. [9bce887](https://github.com/callowayproject/bump-my-version/commit/9bce887cf5e72907ae00b45a7b7f4812dcc2f17e) + + - supersedes the `--list` option + - provides much more capability + - Can output in YAML, JSON, and default + - Can specify one or more items to display + - Can use dotted-notation to pull items from nested data structures. +### Updates + +- Changes bump-my-version into subcommands. [31ffbcf](https://github.com/callowayproject/bump-my-version/commit/31ffbcf839e2491c31d90b51041d1e840371108f) + + - Is backwards-compatible with previous versions + - `bump-my-version` forwards command to `bump-my-version bump` subcommand + - Only problem is that Click will not show help automatically, must provide `--help` + ## 0.5.1 (2023-06-14) [Compare the full difference.](https://github.com/callowayproject/bump-my-version/compare/0.5.0...0.5.1) diff --git a/bumpversion/__init__.py b/bumpversion/__init__.py index 48259ca8..7613b496 100644 --- a/bumpversion/__init__.py +++ b/bumpversion/__init__.py @@ -1,3 +1,3 @@ """Top-level package for bump-my-version.""" -__version__: str = "0.5.1" +__version__: str = "0.5.1.dev6" diff --git a/bumpversion/aliases.py b/bumpversion/aliases.py index 40f17874..cf35ed2a 100644 --- a/bumpversion/aliases.py +++ b/bumpversion/aliases.py @@ -32,6 +32,9 @@ def resolve_command(self, ctx: Context, args: List[str]) -> tuple: # always return the full command name original_args = args[:] _, cmd, args = super().resolve_command(ctx, args) + if cmd.name == "bump" and args != original_args: + if "bump" in original_args: + original_args.remove("bump") return cmd.name, cmd, original_args return cmd.name, cmd, args diff --git a/bumpversion/cli.py b/bumpversion/cli.py index d5d1bf58..411c8ce7 100644 --- a/bumpversion/cli.py +++ b/bumpversion/cli.py @@ -23,6 +23,7 @@ "ignore_unknown_options": True, "allow_interspersed_args": True, }, + add_help_option=False, ) @click.version_option(version=__version__) @click.pass_context diff --git a/pyproject.toml b/pyproject.toml index d7d3243f..2fc1bfb0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -210,7 +210,7 @@ order-by-type = true convention = "google" [tool.bumpversion] -current_version = "0.5.1" +current_version = "0.5.1.dev6" commit = true commit_args = "--no-verify" tag = true diff --git a/tests/test_cli.py b/tests/test_cli.py index 69de1ac6..010ff283 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -26,6 +26,28 @@ def test_bump_no_configured_files(mocker, tmp_path): """ Arrange/Act: Run the `bump` subcommand with --no-configured-files. + Assert: There is no configured files specified to modify + """ + mocked_do_bump = mocker.patch("bumpversion.cli.do_bump") + runner: CliRunner = CliRunner() + with inside_dir(tmp_path): + result: Result = runner.invoke( + cli.cli, ["bump", "--current-version", "1.0.0", "--no-configured-files", "patch"] + ) + + if result.exit_code != 0: + print(result.output) + + assert result.exit_code == 0 + + call_args = mocked_do_bump.call_args[0] + assert len(call_args[2].files) == 0 + + +def test_bump_legacy(mocker, tmp_path): + """ + Arrange/Act: Run the `bump` subcommand with --no-configured-files. + Assert: There is no configured files specified to modify """ mocked_do_bump = mocker.patch("bumpversion.cli.do_bump") @@ -47,7 +69,7 @@ def test_no_configured_files_still_file_args_work(mocker, tmp_path): runner: CliRunner = CliRunner() with inside_dir(tmp_path): result: Result = runner.invoke( - cli.cli, ["--current-version", "1.0.0", "--no-configured-files", "patch", "do-this-file.txt"] + cli.cli, ["bump", "--current-version", "1.0.0", "--no-configured-files", "patch", "do-this-file.txt"] ) if result.exit_code != 0: @@ -65,7 +87,7 @@ def test_missing_explicit_config_file(tmp_path: Path): with inside_dir(tmp_path): runner: CliRunner = CliRunner() with inside_dir(tmp_path): - result: Result = runner.invoke(cli.cli, ["--config-file", "missing-file.cfg"]) + result: Result = runner.invoke(cli.cli, ["bump", "--config-file", "missing-file.cfg"]) assert result.exit_code != 0 assert "'missing-file.cfg' does not exist." in result.output @@ -84,6 +106,7 @@ def test_cli_options_override_config(tmp_path: Path, fixtures_path: Path, mocker result: Result = runner.invoke( cli.cli, [ + "bump", "--config-file", str(config_path), "--current-version", @@ -146,7 +169,9 @@ def test_dirty_work_dir_raises_error(repo: str, scm_command: str, request): runner: CliRunner = CliRunner() # Act - result: Result = runner.invoke(cli.cli, ["patch", "--current-version", "1.1.1", "--no-allow-dirty", "dirty2"]) + result: Result = runner.invoke( + cli.cli, ["bump", "patch", "--current-version", "1.1.1", "--no-allow-dirty", "dirty2"] + ) # Assert assert result.exit_code != 0 @@ -162,7 +187,7 @@ def test_listing_with_version_part(tmp_path: Path, fixtures_path: Path): runner: CliRunner = CliRunner() with inside_dir(tmp_path): - result: Result = runner.invoke(cli.cli, ["--list", "patch"]) + result: Result = runner.invoke(cli.cli, ["bump", "--list", "patch"]) if result.exit_code != 0: print(result.output) @@ -202,7 +227,7 @@ def test_listing_without_version_part(tmp_path: Path, fixtures_path: Path): runner: CliRunner = CliRunner() with inside_dir(tmp_path): - result: Result = runner.invoke(cli.cli, ["--list"]) + result: Result = runner.invoke(cli.cli, ["bump", "--list"]) if result.exit_code != 0: print(result.output) @@ -244,7 +269,7 @@ def test_non_scm_operations_if_scm_not_installed(tmp_path: Path, monkeypatch): runner: CliRunner = CliRunner() # Act - runner.invoke(cli.cli, ["major", "--current-version", "31.0.3", "VERSION"]) + runner.invoke(cli.cli, ["bump", "major", "--current-version", "31.0.3", "VERSION"]) # Assert assert version_path.read_text() == "32.0.0" @@ -267,7 +292,7 @@ def test_detects_bad_or_missing_version_part(version_part: str, tmp_path: Path, version_path.write_text("31.0.3") runner: CliRunner = CliRunner() - args = ["--current-version", "31.0.3"] + args = ["bump", "--current-version", "31.0.3"] if version_part: args.append(version_part) args.append("VERSION")