Browse Source

Enclose main body to main()

Makes it easier to grok the structure and keep the global space clean.
Alois Mahdal 8 years ago
parent
commit
740f30e75e
1 changed files with 28 additions and 26 deletions
  1. 28
    26
      src/bin/satcmd.skel

+ 28
- 26
src/bin/satcmd.skel View File

@@ -42,30 +42,32 @@ usage() {
42 42
             "--version"
43 43
 }
44 44
 
45
-while true; do case $1 in
46
-    -d|--debug)     export SHELLFU_DEBUG=true; shift   ;;
47
-    -v|--verbose)   export SHELLFU_VERBOSE=true; shift ;;
48
-    --version)      saturnin__version; exit            ;;
49
-    --version-semver) echo "$SATURNIN_APP_VERSION"; exit ;;
50
-    -*)             usage;                          ;;
51
-    --*)            usage;                          ;;
52
-    --)             shift; break                    ;;
53
-    "")             usage;                          ;;
54
-    *)              break;                          ;;
55
-esac done
56
-
57
-debug -v SHELLFU_PATH SATURNIN_LIBEXEC SHELLFU_INIGREP_PATH
58
-debug "\$*='$*'"
59
-
60
-export SATURNIN_SUBCOMMAND="$1"
61
-shift
45
+main() {
46
+    local subcommand
47
+    while true; do case $1 in
48
+        -d|--debug)     export SHELLFU_DEBUG=true; shift   ;;
49
+        -v|--verbose)   export SHELLFU_VERBOSE=true; shift ;;
50
+        --version)      saturnin__version; exit            ;;
51
+        --version-semver) echo "$SATURNIN_APP_VERSION"; exit ;;
52
+        -*)             usage;                          ;;
53
+        --*)            usage;                          ;;
54
+        --)             shift; break                    ;;
55
+        "")             usage;                          ;;
56
+        *)              break;                          ;;
57
+    esac done
58
+    subcommand="$1"; shift
59
+    export SATURNIN_SUBCOMMAND="$subcommand"
60
+    debug -v SHELLFU_PATH SATURNIN_LIBEXEC SHELLFU_INIGREP_PATH SATURNIN_SUBCOMMAND
61
+    debug "\$*='$*'"
62
+    case "$subcommand" in
63
+        conf)               inigrep "$@"    ;;
64
+        help)               saturnin__help ;;
65
+        _ls_subcommands)    saturnin__lssc ;;
66
+        _lsfun)             shellfu-get lsfun ;;
67
+        _lsmod)             shellfu-get lsmod ;;
68
+        _ffrun)             ffrun "$@" ;;
69
+        *)                  saturnin__runsc "$@" ;;
70
+    esac
71
+}
62 72
 
63
-case "$SATURNIN_SUBCOMMAND" in
64
-    conf)               inigrep "$@"    ;;
65
-    help)               saturnin__help ;;
66
-    _ls_subcommands)    saturnin__lssc ;;
67
-    _lsfun)             shellfu-get lsfun ;;
68
-    _lsmod)             shellfu-get lsmod ;;
69
-    _ffrun)             ffrun "$@" ;;
70
-    *)                  saturnin__runsc "$@" ;;
71
-esac
73
+main "$@"