Browse Source

Use newer Shellfu interface for handling usage errors

Alois Mahdal 7 years ago
parent
commit
d41d8e0626
2 changed files with 12 additions and 13 deletions
  1. 10
    13
      src/saturnin.sh.skel
  2. 2
    0
      tests/cli/oracle/usage.stderr

+ 10
- 13
src/saturnin.sh.skel View File

173
         -K:*)   ig_mode=$1; ig_query=$2; shift 2; break ;;
173
         -K:*)   ig_mode=$1; ig_query=$2; shift 2; break ;;
174
         -S:*)   ig_mode=$1; ig_query=""; shift 1; break ;;
174
         -S:*)   ig_mode=$1; ig_query=""; shift 1; break ;;
175
         -P:*)   ig_mode=$1; ig_query=""; shift 1; break ;;
175
         -P:*)   ig_mode=$1; ig_query=""; shift 1; break ;;
176
-        .*:*)   warn "bad syntax: $*"; _saturnin__conf_usage ;;
176
+        .*:*)   _saturnin__conf_usage -w "bad syntax: $*" ;;
177
         *.*:*)  ig_mode=-e; ig_query=$1; shift 1; break ;;
177
         *.*:*)  ig_mode=-e; ig_query=$1; shift 1; break ;;
178
-        --help:*) _saturnin__conf_usage -e 0                 ;;
179
-        *)      warn "bad syntax: $*"; _saturnin__conf_usage ;;
178
+        --help:*) _saturnin__conf_usage -e 0            ;;
179
+        *)      _saturnin__conf_usage -w "bad syntax: $*" ;;
180
     esac done
180
     esac done
181
-    test -n "$ig_mode" || { warn "could not determine inigrep mode"; _saturnin__conf_usage; }
181
+    test -n "$ig_mode" || _saturnin__conf_usage -w "could not determine inigrep mode"
182
     debug -v ig_limit ig_query ig_mode Strategy
182
     debug -v ig_limit ig_query ig_mode Strategy
183
     if test -n "$*";
183
     if test -n "$*";
184
     then
184
     then
187
     then
187
     then
188
         files=("${ig_query%%.*}$SATURNIN_CONF_SUFFIX")
188
         files=("${ig_query%%.*}$SATURNIN_CONF_SUFFIX")
189
     else
189
     else
190
-        warn "dunno what to load"
191
-        _saturnin__conf_usage
190
+        _saturnin__conf_usage -w "dunno what to load"
192
     fi
191
     fi
193
     debug -v files
192
     debug -v files
194
     #shellcheck disable=SC2086
193
     #shellcheck disable=SC2086
281
         --version)      saturnin__version;          exit  ;;
280
         --version)      saturnin__version;          exit  ;;
282
         -V|--version-semver) saturnin__get app-version ;;
281
         -V|--version-semver) saturnin__get app-version ;;
283
         --saturnin-get-*) saturnin__get "$1"        ;;
282
         --saturnin-get-*) saturnin__get "$1"        ;;
284
-        -*)             saturnin__usage;            ;;
285
-        --*)            saturnin__usage;            ;;
283
+        -*)             saturnin__usage -w "unknown argument: $1" ;;
284
+        --*)            saturnin__usage -w "unknown argument: $1" ;;
286
         --)             shift; break                ;;
285
         --)             shift; break                ;;
287
-        "")             saturnin__usage;            ;;
286
+        "")             saturnin__usage -w "too few arguments" ;;
288
         *)              break;                      ;;
287
         *)              break;                      ;;
289
     esac done
288
     esac done
290
     subcommand="$1"; shift
289
     subcommand="$1"; shift
389
     binpath+="$SATURNIN_LIBEXEC_PREFIX$subcommand"
388
     binpath+="$SATURNIN_LIBEXEC_PREFIX$subcommand"
390
     debug -v binpath
389
     debug -v binpath
391
     debug "\$*='$*'"
390
     debug "\$*='$*'"
392
-    test -x "$binpath" || {
393
-        warn "invalid sub-command: $subcommand"
394
-        saturnin__usage
395
-    }
391
+    test -x "$binpath" \
392
+     || saturnin__usage "invalid sub-command: $subcommand"
396
     SATURNIN_SUBCOMMAND="$subcommand" "$binpath" "$@"
393
     SATURNIN_SUBCOMMAND="$subcommand" "$binpath" "$@"
397
 }
394
 }
398
 
395
 

+ 2
- 0
tests/cli/oracle/usage.stderr View File

12
   bar
12
   bar
13
   baz
13
   baz
14
   foo
14
   foo
15
+
16
+bad usage: too few arguments