From 69b588da86265db1e581d13c1c438640b0a9b853 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 9 May 2022 21:19:24 -0500 Subject: [PATCH] Add current-version cli command --- README.rst | 6 ++++++ tbump/cli.py | 10 ++++++++++ tbump/test/test_cli.py | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/README.rst b/README.rst index a2416a8..adc6081 100644 --- a/README.rst +++ b/README.rst @@ -150,6 +150,12 @@ You can use ``--non-interactive`` to disable this behavior. If you only want to bump the files without performing any git actions or running the hook commands, use the ``--only-patch`` option. +The current version of the project can be found using the command: + +.. code-block:: console + + $ tbump current-version + Advanced configuration ---------------------- diff --git a/tbump/cli.py b/tbump/cli.py index 7152488..8342370 100644 --- a/tbump/cli.py +++ b/tbump/cli.py @@ -23,6 +23,7 @@ """ Usage: tbump [options] + tbump [options] current-version tbump [options] init [--pyproject] tbump --help tbump --version @@ -92,6 +93,15 @@ def run(cmd: List[str]) -> None: return new_version = opt_dict[""] + + if new_version == 'current-version': + config_file = get_config_file( + working_path, specified_config_path=specified_config_path + ) + config = config_file.get_config() + ui.info(config.current_version) + return + bump_options = BumpOptions( working_path=working_path, new_version=new_version, diff --git a/tbump/test/test_cli.py b/tbump/test/test_cli.py index 76740b9..a9d3358 100644 --- a/tbump/test/test_cli.py +++ b/tbump/test/test_cli.py @@ -1,4 +1,5 @@ from pathlib import Path +import subprocess from typing import Any, Optional import pytest @@ -123,6 +124,8 @@ def test_end_to_end_using_tbump_toml(test_repo: Path) -> None: assert bump_done(test_repo, previous_commit) + output = subprocess.check_output(["tbump", "current-version"], cwd=test_repo) + assert output.decode('utf-8').strip() == '1.2.41-alpha-2' def test_end_to_end_using_pyproject_toml(test_pyproject_repo: Path) -> None: _, previous_commit = run_git_captured(test_pyproject_repo, "rev-parse", "HEAD") @@ -138,6 +141,9 @@ def test_end_to_end_using_pyproject_toml(test_pyproject_repo: Path) -> None: actual = foo_py.read_text() assert "0.2.0" in actual + output = subprocess.check_output(["tbump", "current-version"], cwd=test_pyproject_repo) + assert output.decode('utf-8').strip() == '0.2.0' + def test_using_specified_path( test_repo: Path, @@ -160,6 +166,9 @@ def test_using_specified_path( assert files_bumped(test_repo, config_path=config_path) + output = subprocess.check_output(["tbump", "current-version", "-C", str(test_repo), '--config', str(config_path)], cwd=test_repo) + assert output.decode('utf-8').strip() == '1.2.41-alpha-2' + def test_dry_run_interactive(test_repo: Path) -> None: _, previous_commit = run_git_captured(test_repo, "rev-parse", "HEAD")