Skip to content

Commit

Permalink
Add current-version cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored and dmerejkowsky committed May 14, 2022
1 parent f3bdce7 commit 69b588d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------------

Expand Down
10 changes: 10 additions & 0 deletions tbump/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"""
Usage:
tbump [options] <new_version>
tbump [options] current-version
tbump [options] init [--pyproject] <current_version>
tbump --help
tbump --version
Expand Down Expand Up @@ -92,6 +93,15 @@ def run(cmd: List[str]) -> None:
return

new_version = opt_dict["<new_version>"]

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,
Expand Down
9 changes: 9 additions & 0 deletions tbump/test/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
import subprocess
from typing import Any, Optional

import pytest
Expand Down Expand Up @@ -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")
Expand All @@ -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,
Expand All @@ -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")
Expand Down

0 comments on commit 69b588d

Please sign in to comment.