Browse Source

improved option parser with __empty and __unknown

Jaromil 2 years ago
parent
commit
d59b4d64cb
2 changed files with 10 additions and 6 deletions
  1. 6 6
      zuper
  2. 4 0
      zuper.init

+ 6 - 6
zuper

@@ -942,13 +942,13 @@ option.parse() {
942 942
     unset discardme
943 943
     subcommand=${1}
944 944
     if [[ -z $subcommand ]]; then
945
-        subcommand="__default"
945
+        subcommand="__empty"
946 946
     fi
947 947
 
948 948
     if [[ -z ${(k)option_subcommands[$subcommand]} ]]; then
949
-        _warning "There's no such command \"::1 subcommand::\"." $subcommand
950
-		_failure "Please try -h for help."
951
-		return 1
949
+		subcommand="__unknown:$subcommand"
950
+        # _warning "There's no such command \"::1 subcommand::\"." $subcommand
951
+		# _failure "Please try -h for help."
952 952
     fi
953 953
     argv=("${(@)oldstar}")
954 954
     unset oldstar
@@ -981,7 +981,7 @@ option.parse() {
981 981
         option_params+=$arg
982 982
     done
983 983
     # First parameter actually is the subcommand: delete it and shift
984
-    [[ $subcommand != '__default' ]] && { option_params[1]=(); shift }
984
+    [[ $subcommand != '__empty' ]] && { option_params[1]=(); shift }
985 985
 
986 986
     ### End parsing command-specific options
987 987
 
@@ -998,7 +998,7 @@ option.parse() {
998 998
 # 	help)
999 999
 # 		print "TODO: help"
1000 1000
 # 		;;
1001
-# 	__default)
1001
+# 	__empty)
1002 1002
 # 		zdump
1003 1003
 # 		;;
1004 1004
 

+ 4 - 0
zuper.init

@@ -26,6 +26,10 @@ tmpfiles=()
26 26
 config_section=()
27 27
 config_section_type=${config_section_type:-org-mode}
28 28
 
29
+option_subcommands[__empty]=""
30
+option_subcommands[__unknown]=""
31
+
32
+
29 33
 
30 34
 func "Zuper $zuper_version initialized"
31 35
 func "${#vars} global variables registered"