From d59b4d64cb66b603771737678803dcd95b63af24 Mon Sep 17 00:00:00 2001 From: Jaromil Date: Mon, 27 Feb 2017 15:52:04 +0100 Subject: [PATCH] improved option parser with __empty and __unknown --- zuper | 12 ++++++------ zuper.init | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/zuper b/zuper index 5bedaa0..6d0cbf9 100755 --- a/zuper +++ b/zuper @@ -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 # ;; diff --git a/zuper.init b/zuper.init index 2a9a395..9162015 100644 --- a/zuper.init +++ b/zuper.init @@ -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"