소스 검색

Use newer Shellfu interface for handling usage errors

Alois Mahdal 7 년 전
부모
커밋
d41d8e0626
2개의 변경된 파일12개의 추가작업 그리고 13개의 파일을 삭제
  1. 10
    13
      src/saturnin.sh.skel
  2. 2
    0
      tests/cli/oracle/usage.stderr

+ 10
- 13
src/saturnin.sh.skel 파일 보기

@@ -173,12 +173,12 @@ saturnin__conf() {
173 173
         -K:*)   ig_mode=$1; ig_query=$2; shift 2; break ;;
174 174
         -S:*)   ig_mode=$1; ig_query=""; shift 1; break ;;
175 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 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 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 182
     debug -v ig_limit ig_query ig_mode Strategy
183 183
     if test -n "$*";
184 184
     then
@@ -187,8 +187,7 @@ saturnin__conf() {
187 187
     then
188 188
         files=("${ig_query%%.*}$SATURNIN_CONF_SUFFIX")
189 189
     else
190
-        warn "dunno what to load"
191
-        _saturnin__conf_usage
190
+        _saturnin__conf_usage -w "dunno what to load"
192 191
     fi
193 192
     debug -v files
194 193
     #shellcheck disable=SC2086
@@ -281,10 +280,10 @@ saturnin__main() {
281 280
         --version)      saturnin__version;          exit  ;;
282 281
         -V|--version-semver) saturnin__get app-version ;;
283 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 285
         --)             shift; break                ;;
287
-        "")             saturnin__usage;            ;;
286
+        "")             saturnin__usage -w "too few arguments" ;;
288 287
         *)              break;                      ;;
289 288
     esac done
290 289
     subcommand="$1"; shift
@@ -389,10 +388,8 @@ saturnin__runsc() {
389 388
     binpath+="$SATURNIN_LIBEXEC_PREFIX$subcommand"
390 389
     debug -v binpath
391 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 393
     SATURNIN_SUBCOMMAND="$subcommand" "$binpath" "$@"
397 394
 }
398 395
 

+ 2
- 0
tests/cli/oracle/usage.stderr 파일 보기

@@ -12,3 +12,5 @@ commands:
12 12
   bar
13 13
   baz
14 14
   foo
15
+
16
+bad usage: too few arguments