From c4b419d98ea328a11322dea76e2d500592c3bfc1 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Mon, 21 Dec 2020 16:53:44 -0600 Subject: [PATCH] Add --version and --help as yadm internal commands (#267) --- test/test_help.py | 6 ++++-- test/test_hooks.py | 5 +++-- test/test_version.py | 5 +++-- yadm | 5 +++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/test/test_help.py b/test/test_help.py index 37ac323..0d8f2c3 100644 --- a/test/test_help.py +++ b/test/test_help.py @@ -1,4 +1,5 @@ """Test help""" +import pytest def test_missing_command(runner, yadm_cmd): @@ -9,9 +10,10 @@ def test_missing_command(runner, yadm_cmd): assert run.out.startswith('Usage: yadm') -def test_help_command(runner, yadm_cmd): +@pytest.mark.parametrize('cmd', ['--help', 'help']) +def test_help_command(runner, yadm_cmd, cmd): """Run with help command""" - run = runner(command=yadm_cmd('help')) + run = runner(command=yadm_cmd(cmd)) assert run.failure assert run.err == '' assert run.out.startswith('Usage: yadm') diff --git a/test/test_hooks.py b/test/test_hooks.py index 19eb95c..01a524a 100644 --- a/test/test_hooks.py +++ b/test/test_hooks.py @@ -21,8 +21,9 @@ import pytest 'pre-post-success', 'pre-post-fail', ]) +@pytest.mark.parametrize('cmd', ['--version', 'version']) def test_hooks( - runner, yadm_cmd, paths, + runner, yadm_cmd, paths, cmd, pre, pre_code, post, post_code): """Test pre/post hook""" @@ -33,7 +34,7 @@ def test_hooks( create_hook(paths, 'post_version', post_code) # run yadm - run = runner(yadm_cmd('version')) + run = runner(yadm_cmd(cmd)) # when a pre hook fails, yadm should exit with the hook's code assert run.code == pre_code assert run.err == '' diff --git a/test/test_version.py b/test/test_version.py index fca5d7b..08bebe1 100644 --- a/test/test_version.py +++ b/test/test_version.py @@ -26,10 +26,11 @@ def test_semantic_version(expected_version): 'does not conform to MAJOR.MINOR.PATCH') +@pytest.mark.parametrize('cmd', ['--version', 'version']) def test_reported_version( - runner, yadm_cmd, expected_version): + runner, yadm_cmd, cmd, expected_version): """Report correct version""" - run = runner(command=yadm_cmd('version')) + run = runner(command=yadm_cmd(cmd)) assert run.success assert run.err == '' assert run.out == f'yadm {expected_version}\n' diff --git a/yadm b/yadm index 36b3abb..2159aa5 100755 --- a/yadm +++ b/yadm @@ -93,13 +93,14 @@ function main() { # parse command line arguments local retval=0 - internal_commands="^(alt|bootstrap|clean|clone|config|decrypt|encrypt|enter|git-crypt|help|init|introspect|list|perms|transcrypt|upgrade|version)$" + internal_commands="^(alt|bootstrap|clean|clone|config|decrypt|encrypt|enter|git-crypt|help|--help|init|introspect|list|perms|transcrypt|upgrade|version|--version)$" if [ -z "$*" ] ; then # no argumnts will result in help() help elif [[ "$1" =~ $internal_commands ]] ; then # for internal commands, process all of the arguments - YADM_COMMAND="${1/-/_}" + YADM_COMMAND="${1//-/_}" + YADM_COMMAND="${YADM_COMMAND/__/}" YADM_ARGS=() shift