Просмотр исходного кода

Use variable to hold shellfu() sub-command

Alois Mahdal 8 лет назад
Родитель
Сommit
5389d9f0ce
1 измененных файлов: 15 добавлений и 17 удалений
  1. 15
    17
      src/shellfu.sh.skel

+ 15
- 17
src/shellfu.sh.skel Просмотреть файл

@@ -59,6 +59,7 @@ SHELLFU_VERSION=__MKIT_PROJ_VERSION__
59 59
 __SHELLFU_IMPORTED=${__SHELLFU_IMPORTED:-}
60 60
 
61 61
 shellfu() {
62
+    local cmd=$1; shift
62 63
 
63 64
     # debug on import
64 65
     case $SHELLFU_DEBUGINIT:$1 in
@@ -77,28 +78,25 @@ shellfu() {
77 78
             ;;
78 79
     esac
79 80
 
80
-    case $1 in
81
+    case $cmd in
81 82
         __debug)
82 83
             $SHELLFU_DEBUGINIT || return 0
83
-            shift
84 84
             echo "debug: $*" >&2
85 85
             ;;
86 86
         __die)
87
-            shift
88 87
             echo "$@" >&2
89 88
             test -z "$PS1" && exit 3
90 89
             return 3
91 90
             ;;
92 91
         __warn)
93
-            shift
94 92
             echo "$@" >&2
95 93
             ;;
96 94
 
97 95
         import)
98 96
             #
99
-            # Import module named $2
97
+            # Import module named $1
100 98
             #
101
-            local mname=$2
99
+            local mname=$1
102 100
             shellfu _is_imported "$mname" && return 0
103 101
             if shellfu _do_import "$mname";
104 102
             then
@@ -109,18 +107,18 @@ shellfu() {
109 107
             ;;
110 108
         try_import)
111 109
             #
112
-            # Try if module $2 could be imported
110
+            # Try if module $1 could be imported
113 111
             #
114
-            local mname=$2
112
+            local mname=$1
115 113
             ( shellfu _do_import "$mname" )
116 114
             ;;
117 115
 
118 116
         _do_import)
119 117
             #
120
-            # Really import module named $2
118
+            # Really import module named $1
121 119
             #
122 120
             $SHELLFU_EMBEDDED && return 0
123
-            local mname=$2
121
+            local mname=$1
124 122
             local es=4
125 123
             local mpath
126 124
             shellfu __debug "importing module $mname"
@@ -145,17 +143,17 @@ shellfu() {
145 143
             ;;
146 144
         _is_imported)
147 145
             #
148
-            # True if module $2 is already imported
146
+            # True if module $1 is already imported
149 147
             #
150
-            local mname=$2
148
+            local mname=$1
151 149
             echo "$__SHELLFU_IMPORTED" | tr : \\n | grep -qx "$mname"
152 150
             ;;
153 151
 
154 152
         _list_mfiles)
155 153
             #
156
-            # Find module files of module matching $2 (wildcard expression)
154
+            # Find module files of module matching $1 (wildcard expression)
157 155
             #
158
-            local ex="${2:-*}"
156
+            local ex="${1:-*}"
159 157
             local incdir
160 158
             echo "$SHELLFU_INCLUDE-sh:$SHELLFU_INCLUDE-$SHELLFU_COMPAT:$SHELLFU_PATH" \
161 159
               | tr ":" '\n' \
@@ -170,13 +168,13 @@ shellfu() {
170 168
             ;;
171 169
         _select_mfile)
172 170
             #
173
-            # Select file that contains module named $2
171
+            # Select file that contains module named $1
174 172
             #
175
-            shellfu _list_mfiles "$2" | head -1
173
+            shellfu _list_mfiles "$1" | head -1
176 174
             ;;
177 175
 
178 176
         *)
179
-            shellfu __die "unknown shellfu command: $1"
177
+            shellfu __die "unknown shellfu command: $cmd"
180 178
             ;;
181 179
     esac
182 180
 }