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

View File

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