From 1dc556ec175090823313d6bb4e45e7da6cb951b6 Mon Sep 17 00:00:00 2001 From: dtrai2 Date: Fri, 17 May 2024 20:35:05 +0200 Subject: [PATCH 1/2] add version option to cli --- README.md | 2 ++ g2b/g2b.py | 1 + tests/test_g2b.py | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 6e4b12b..a830e8d 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ To install `gnucash to beancount` simply use `pip`: pip install g2b ``` +Test with ``g2b --version`` if the installation was successful. + ## Usage ### Create Configuration for g2b diff --git a/g2b/g2b.py b/g2b/g2b.py index 7d71344..62f3478 100644 --- a/g2b/g2b.py +++ b/g2b/g2b.py @@ -299,6 +299,7 @@ def _get_open_account_directives(self, transactions): @click.command() +@click.version_option(message="%(version)s") @click.option( "--input", "-i", diff --git a/tests/test_g2b.py b/tests/test_g2b.py index ffa5c95..239cfda 100644 --- a/tests/test_g2b.py +++ b/tests/test_g2b.py @@ -3,6 +3,7 @@ # pylint: disable=protected-access import datetime import re +from importlib.metadata import version from pathlib import Path, PosixPath from unittest import mock @@ -52,6 +53,11 @@ def test_cli_raises_on_non_existing_config_file(self, tmp_path): r".*Path 'test_config.yml' does not exist.*", result.output, flags=re.DOTALL ) + def test_cli_version(self): + result = self.cli_runner.invoke(main, "--version") + assert result.exit_code == 0, f"{result.exc_info}" + assert version('g2b') in result.output + class TestGnuCash2Beancount: From 84684224ad612c1bd6ab101980573c3ad34d65b4 Mon Sep 17 00:00:00 2001 From: dtrai2 Date: Fri, 17 May 2024 20:37:01 +0200 Subject: [PATCH 2/2] align markdown quotes and fix black --- README.md | 2 +- tests/test_g2b.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a830e8d..9a77d62 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ To install `gnucash to beancount` simply use `pip`: pip install g2b ``` -Test with ``g2b --version`` if the installation was successful. +Test with `g2b --version` if the installation was successful. ## Usage diff --git a/tests/test_g2b.py b/tests/test_g2b.py index 239cfda..fe78822 100644 --- a/tests/test_g2b.py +++ b/tests/test_g2b.py @@ -56,7 +56,7 @@ def test_cli_raises_on_non_existing_config_file(self, tmp_path): def test_cli_version(self): result = self.cli_runner.invoke(main, "--version") assert result.exit_code == 0, f"{result.exc_info}" - assert version('g2b') in result.output + assert version("g2b") in result.output class TestGnuCash2Beancount: