feat: allow command line flags to be used in any order#41
feat: allow command line flags to be used in any order#41zanona wants to merge 1 commit intosdushantha:masterfrom zanona:master
Conversation
|
Hi! Do you get the same when running you can also do from the project directory: alias tmpmail=./tmpmail
bash tmpmail --help |
|
Ah, I believe we have a compatibility issue here, where https://stackoverflow.com/questions/12152077
Apologies for having missed this previously as it works well on Linux. Just in case someone's interested, below is a sample of how to workaround source: https://stackoverflow.com/a/28466267/165750 die() { echo "$*" >&2; exit 2; } # complain to STDERR and exit with error
needs_arg() { if [ -z "$OPTARG" ]; then die "No arg for --$OPT option"; fi; }
while getopts ab:c:-: OPT; do
# support long options: https://stackoverflow.com/a/28466267/519360
if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG
OPT="${OPTARG%%=*}" # extract long option name
OPTARG="${OPTARG#$OPT}" # extract long option argument (may be empty)
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
fi
case "$OPT" in
a | alpha ) alpha=true ;;
b | bravo ) needs_arg; bravo="$OPTARG" ;;
c | charlie ) needs_arg; charlie="$OPTARG" ;;
??* ) die "Illegal option --$OPT" ;; # bad long option
? ) exit 2 ;; # bad short option (error reported via getopts)
esac
done
shift $((OPTIND-1)) # remove parsed options and args from $@ list
|


This PR allows using option arguments in any position by depending on
getoptresolve #1