improved option parser with __empty and __unknown

This commit is contained in:
Jaromil 2017-02-27 15:52:04 +01:00
parent 7e70209e21
commit d59b4d64cb
2 changed files with 10 additions and 6 deletions

12
zuper
View File

@ -942,13 +942,13 @@ option.parse() {
unset discardme
subcommand=${1}
if [[ -z $subcommand ]]; then
subcommand="__default"
subcommand="__empty"
fi
if [[ -z ${(k)option_subcommands[$subcommand]} ]]; then
_warning "There's no such command \"::1 subcommand::\"." $subcommand
_failure "Please try -h for help."
return 1
subcommand="__unknown:$subcommand"
# _warning "There's no such command \"::1 subcommand::\"." $subcommand
# _failure "Please try -h for help."
fi
argv=("${(@)oldstar}")
unset oldstar
@ -981,7 +981,7 @@ option.parse() {
option_params+=$arg
done
# First parameter actually is the subcommand: delete it and shift
[[ $subcommand != '__default' ]] && { option_params[1]=(); shift }
[[ $subcommand != '__empty' ]] && { option_params[1]=(); shift }
### End parsing command-specific options
@ -998,7 +998,7 @@ option.parse() {
# help)
# print "TODO: help"
# ;;
# __default)
# __empty)
# zdump
# ;;

View File

@ -26,6 +26,10 @@ tmpfiles=()
config_section=()
config_section_type=${config_section_type:-org-mode}
option_subcommands[__empty]=""
option_subcommands[__unknown]=""
func "Zuper $zuper_version initialized"
func "${#vars} global variables registered"