Add --version and --help as yadm internal commands (#267)
This commit is contained in:
parent
e3d2ea2863
commit
c4b419d98e
4 changed files with 13 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
||||||
"""Test help"""
|
"""Test help"""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
def test_missing_command(runner, yadm_cmd):
|
def test_missing_command(runner, yadm_cmd):
|
||||||
|
@ -9,9 +10,10 @@ def test_missing_command(runner, yadm_cmd):
|
||||||
assert run.out.startswith('Usage: yadm')
|
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 with help command"""
|
||||||
run = runner(command=yadm_cmd('help'))
|
run = runner(command=yadm_cmd(cmd))
|
||||||
assert run.failure
|
assert run.failure
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
assert run.out.startswith('Usage: yadm')
|
assert run.out.startswith('Usage: yadm')
|
||||||
|
|
|
@ -21,8 +21,9 @@ import pytest
|
||||||
'pre-post-success',
|
'pre-post-success',
|
||||||
'pre-post-fail',
|
'pre-post-fail',
|
||||||
])
|
])
|
||||||
|
@pytest.mark.parametrize('cmd', ['--version', 'version'])
|
||||||
def test_hooks(
|
def test_hooks(
|
||||||
runner, yadm_cmd, paths,
|
runner, yadm_cmd, paths, cmd,
|
||||||
pre, pre_code, post, post_code):
|
pre, pre_code, post, post_code):
|
||||||
"""Test pre/post hook"""
|
"""Test pre/post hook"""
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ def test_hooks(
|
||||||
create_hook(paths, 'post_version', post_code)
|
create_hook(paths, 'post_version', post_code)
|
||||||
|
|
||||||
# run yadm
|
# 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
|
# when a pre hook fails, yadm should exit with the hook's code
|
||||||
assert run.code == pre_code
|
assert run.code == pre_code
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
|
|
|
@ -26,10 +26,11 @@ def test_semantic_version(expected_version):
|
||||||
'does not conform to MAJOR.MINOR.PATCH')
|
'does not conform to MAJOR.MINOR.PATCH')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('cmd', ['--version', 'version'])
|
||||||
def test_reported_version(
|
def test_reported_version(
|
||||||
runner, yadm_cmd, expected_version):
|
runner, yadm_cmd, cmd, expected_version):
|
||||||
"""Report correct version"""
|
"""Report correct version"""
|
||||||
run = runner(command=yadm_cmd('version'))
|
run = runner(command=yadm_cmd(cmd))
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
assert run.out == f'yadm {expected_version}\n'
|
assert run.out == f'yadm {expected_version}\n'
|
||||||
|
|
5
yadm
5
yadm
|
@ -93,13 +93,14 @@ function main() {
|
||||||
|
|
||||||
# parse command line arguments
|
# parse command line arguments
|
||||||
local retval=0
|
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
|
if [ -z "$*" ] ; then
|
||||||
# no argumnts will result in help()
|
# no argumnts will result in help()
|
||||||
help
|
help
|
||||||
elif [[ "$1" =~ $internal_commands ]] ; then
|
elif [[ "$1" =~ $internal_commands ]] ; then
|
||||||
# for internal commands, process all of the arguments
|
# for internal commands, process all of the arguments
|
||||||
YADM_COMMAND="${1/-/_}"
|
YADM_COMMAND="${1//-/_}"
|
||||||
|
YADM_COMMAND="${YADM_COMMAND/__/}"
|
||||||
YADM_ARGS=()
|
YADM_ARGS=()
|
||||||
shift
|
shift
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue