Only match command input at the start of the command string
This commit is contained in:
parent
0c2930f98d
commit
182164b6ae
|
@ -5,10 +5,20 @@ setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
test_get_command_returns_list_for_substring() {
|
test_get_command_returns_list_for_substring() {
|
||||||
|
commands="list new"
|
||||||
expected="list"
|
expected="list"
|
||||||
|
|
||||||
for arg in l li lis list; do
|
for arg in l li lis list; do
|
||||||
result="$(get_command "$arg")"
|
result="$(get_command "$commands" "$arg")"
|
||||||
assert_equals "$expected" "$result"
|
assert_equals "$expected" "$result"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_get_command_does_not_return_match_unless_at_start_of_command_string() {
|
||||||
|
commands="delete"
|
||||||
|
expected=""
|
||||||
|
|
||||||
|
result="$(get_command "$commands" "l")"
|
||||||
|
|
||||||
|
assert_equals "$expected" "$result"
|
||||||
|
}
|
||||||
|
|
14
zk
14
zk
|
@ -1,20 +1,24 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
COMMANDS='list'
|
COMMANDS='list new delete'
|
||||||
|
|
||||||
get_command() {
|
get_command() {
|
||||||
for c in $COMMANDS; do
|
commands="$1"
|
||||||
if echo "$c" | grep "$1" >/dev/null; then
|
input="$2"
|
||||||
|
|
||||||
|
for c in $commands; do
|
||||||
|
if echo "$c" | grep "^$input" >/dev/null; then
|
||||||
echo "$c"
|
echo "$c"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
echo "Hello, world"
|
subcommand="$(get_commands "$COMMANDS" "$1")"
|
||||||
|
echo "$subcommand"
|
||||||
}
|
}
|
||||||
|
|
||||||
name="$(basename "$0")"
|
name="$(basename "$0")"
|
||||||
if test "$name" = "zk"; then
|
if test "$name" = "zk"; then
|
||||||
main
|
main "$@"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue