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() {
|
||||
commands="list new"
|
||||
expected="list"
|
||||
|
||||
for arg in l li lis list; do
|
||||
result="$(get_command "$arg")"
|
||||
result="$(get_command "$commands" "$arg")"
|
||||
assert_equals "$expected" "$result"
|
||||
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
|
||||
|
||||
COMMANDS='list'
|
||||
COMMANDS='list new delete'
|
||||
|
||||
get_command() {
|
||||
for c in $COMMANDS; do
|
||||
if echo "$c" | grep "$1" >/dev/null; then
|
||||
commands="$1"
|
||||
input="$2"
|
||||
|
||||
for c in $commands; do
|
||||
if echo "$c" | grep "^$input" >/dev/null; then
|
||||
echo "$c"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
echo "Hello, world"
|
||||
subcommand="$(get_commands "$COMMANDS" "$1")"
|
||||
echo "$subcommand"
|
||||
}
|
||||
|
||||
name="$(basename "$0")"
|
||||
if test "$name" = "zk"; then
|
||||
main
|
||||
main "$@"
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue