From 0fd2f72d49c4ed36309e9a1580b59bc0ed20b8a9 Mon Sep 17 00:00:00 2001 From: Patrick Elmer Date: Sun, 8 Mar 2026 21:03:24 +0100 Subject: [PATCH 1/4] Enable -V for version --- magicli.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/magicli.py b/magicli.py index e0a79d1..377d4c6 100644 --- a/magicli.py +++ b/magicli.py @@ -168,7 +168,11 @@ def check_for_version(argv, parameters, docstring, module): "version" not in parameters and any( (argv == [arg] and string in docstring) - for arg, string in [("--version", "--version"), ("-v", "-v, --version")] + for arg, string in [ + ("--version", "--version"), + ("-v", "-v, --version"), + ("-V", "-V, --version"), + ] ) and module ): From eb5da0f81d54f03b83cd0cdb6748ca23bbe0e710 Mon Sep 17 00:00:00 2001 From: Patrick Elmer Date: Sun, 8 Mar 2026 21:03:41 +0100 Subject: [PATCH 2/4] Fix typos --- magicli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/magicli.py b/magicli.py index 377d4c6..063abcf 100644 --- a/magicli.py +++ b/magicli.py @@ -38,7 +38,7 @@ def magicli(): def is_command(argv, module): """ Checks if the first argument is a valid command in the module and returns - the function to call if `argv[0]` is public and not excluded in `__all__`, + the function to call if `argv[0]` is public and not excluded in `__all__`. """ if ( argv @@ -110,7 +110,7 @@ def parse_short_options(short_options, docstring, iter_argv, parameters, kwargs) def short_to_long_option(short, docstring): """ - Converts a one character short option to a long option accoring to the help message. + Converts a one character short option to a long option according to the help message. """ template = f"-{short}, --" if (start := docstring.find(template)) != -1: From bd8f5ed11ef767734a0f44c6149a2b44224eb8ab Mon Sep 17 00:00:00 2001 From: Patrick Elmer Date: Mon, 9 Mar 2026 07:38:53 +0100 Subject: [PATCH 3/4] Add test for -V --- tests/test_magicli.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_magicli.py b/tests/test_magicli.py index f2555e9..6281e9f 100644 --- a/tests/test_magicli.py +++ b/tests/test_magicli.py @@ -10,7 +10,7 @@ def name(): - "--version" + "-V, --version" global ANSWER ANSWER = 1 @@ -101,11 +101,12 @@ def test_short_option_with_wrong_type(mocked): @mock.patch("importlib.import_module", side_effect=module_version) def test_version(mocked, capsys): - sys.argv = ["name", "--version"] - with pytest.raises(SystemExit) as error: - magicli() - assert error.value.code is None - assert capsys.readouterr()[0] == "1.2.3\n" + for version in ["--version", "-V"]: + sys.argv = ["name", version] + with pytest.raises(SystemExit) as error: + magicli() + assert error.value.code is None + assert capsys.readouterr()[0] == "1.2.3\n" sys.argv = ["name", "-v"] with pytest.raises(SystemExit) as error: From 29b2d8387fbbd44ac7f3c3101cd813e375379805 Mon Sep 17 00:00:00 2001 From: Patrick Elmer Date: Mon, 9 Mar 2026 07:39:04 +0100 Subject: [PATCH 4/4] Fix typo --- magicli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/magicli.py b/magicli.py index 063abcf..c335879 100644 --- a/magicli.py +++ b/magicli.py @@ -238,7 +238,7 @@ def load_module(name): def get_commands(module): - """Returns list of public commands, unless not present in `__all__`.""" + """Returns list of public commands that are not present in `__all__`.""" return [ name for name, _ in inspect.getmembers(module, inspect.isfunction)