wcarhart / koi

Bashful argument parsing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Joint arguments with an invalid arg does not result in an error

wcarhart opened this issue · comments

Suppose:

#!/bin/bash
source koi
koirequirehelpactions=0

function myfunction {
  __addarg "" "--flag" "flag" "optional" "" "help text"
  __addarg "-g" "--glad" "flag" "optional" "" "help text"
  __parseargs "$@"
  echo "flag: $flag"
  echo "glad: $glad"
}

__koirun "$@"

Run with:

./myscript.sh myfunction -fg
flag: 0
glad: 1

This should result in an error because the -f option is not defined.

Also occurs with the new dependent argument functionality:

__addarg "-h" "--help" "help" "optional" "" "help text"
__addarg "-a" "--arg" "storevalue" "optional" "" "help text"
__addarg "-f" "--flag" "flag" "optional" "" "help text"
__addarg "-g" "--glad" "flag" "optional" "" "help text"
__addgroup "flags" "XOR" "optional" "--flag" "--glad"
__adddep "--flag" "--glad" "dependson" "--arg"
__parseargs "$@"

Run with:

./myscript myfunction -fg -a abc

Gives invalid error:

err: '--flag' must be used with '--arg'

There should be a unit test for this.

I was mistaken, this bug is not present in the __adddep example above. There should still be a unit test for it, though.