1
0
Fork 0
mirror of synced 2024-12-21 22:21:08 -05:00

Add --version and --help as yadm internal commands (#267)

This commit is contained in:
Tim Byrne 2020-12-21 16:53:44 -06:00
parent e3d2ea2863
commit c4b419d98e
No known key found for this signature in database
GPG key ID: 14DB4FC2465A4B12
4 changed files with 13 additions and 8 deletions

View file

@ -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')

View file

@ -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 == ''

View file

@ -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'

5
yadm
View file

@ -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