浏览代码

Allow overriding generator, selector and consumer on command line

Allow overriding each of the essential parts at CLI, in which case do
not load them from INI.
Alois Mahdal 10 年前
父节点
当前提交
256d6f51f7
共有 1 个文件被更改,包括 31 次插入13 次删除
  1. 31
    13
      src/libexec/saturnin-menu

+ 31
- 13
src/libexec/saturnin-menu 查看文件

6
 ffoo import pretty
6
 ffoo import pretty
7
 
7
 
8
 usage() {
8
 usage() {
9
-    mkusage "[name]"
9
+    mkusage "[-g generator_cmd] [-s selector_cmd] [-c consumer_cmd] [name]"
10
 }
10
 }
11
 
11
 
12
 SATURNIN_MENU_MNAME=""
12
 SATURNIN_MENU_MNAME=""
17
 
17
 
18
 load_parts() {
18
 load_parts() {
19
     #
19
     #
20
-    # Load mandatory parts
20
+    # Load mandatory parts for menu name $1
21
     #
21
     #
22
     local mname
22
     local mname
23
-    mname=$(get_mname) || usage
23
+
24
+    # last chance to get mname
25
+    test -n "$SATURNIN_MENU_MNAME" \
26
+     || SATURNIN_MENU_MNAME="$(get_mname)" \
27
+     || usage
28
+    mname="$SATURNIN_MENU_MNAME"
29
+
30
+    # check that menu item exists
24
     inigrep -s menu.$mname | grep -q . \
31
     inigrep -s menu.$mname | grep -q . \
25
      || die "no such menu: $mname"
32
      || die "no such menu: $mname"
26
-    SATURNIN_MENU_GENERATOR="$(get_generator)"  \
33
+
34
+    test -n "$SATURNIN_MENU_GENERATOR" \
35
+     || SATURNIN_MENU_GENERATOR="$(get_generator)"  \
27
      || die "cannot find generator for menu: $mname"
36
      || die "cannot find generator for menu: $mname"
28
-    SATURNIN_MENU_SELECTOR="$(get_selector)" \
37
+
38
+    test -n "$SATURNIN_MENU_SELECTOR" \
39
+     || SATURNIN_MENU_SELECTOR="$(get_selector)" \
29
      || die "cannot find selector for menu: $mname"
40
      || die "cannot find selector for menu: $mname"
30
-    SATURNIN_MENU_SELECT_ARGS="$(get_select_args)"
31
-    SATURNIN_MENU_CONSUMER="$(get_consumer)" \
41
+
42
+    test -n "$SATURNIN_MENU_SELECT_ARGS" \
43
+     || SATURNIN_MENU_SELECT_ARGS="$(get_select_args)"
44
+
45
+    test -n "$SATURNIN_MENU_CONSUMER" \
46
+     || SATURNIN_MENU_CONSUMER="$(get_consumer)" \
32
      || die "cannot find consumer for menu: $mname"
47
      || die "cannot find consumer for menu: $mname"
33
 }
48
 }
34
 
49
 
35
 get_mname() {
50
 get_mname() {
36
     #
51
     #
37
-    # If not set, take from global INI default
52
+    # Take from global INI default
38
     #
53
     #
39
-    test -n "$SATURNIN_MENU_MNAME" && {
40
-        printf '%s' "$SATURNIN_MENU_MNAME"
41
-        return 0
42
-    }
43
     inigrep -1 -p menu._default_.name | grep .
54
     inigrep -1 -p menu._default_.name | grep .
44
 }
55
 }
45
 
56
 
125
     eval "$SATURNIN_MENU_CONSUMER"
136
     eval "$SATURNIN_MENU_CONSUMER"
126
 }
137
 }
127
 
138
 
128
-SATURNIN_MENU_MNAME="$1"
139
+while true; do case "$1" in
140
+    -g) SATURNIN_MENU_GENERATOR="$2"; shift; shift ;;
141
+    -s) SATURNIN_MENU_SELECTOR="$2"; shift; shift ;;
142
+    -c) SATURNIN_MENU_CONSUMER="$2"; shift; shift ;;
143
+    -*) usage ;;
144
+    "") usage ;;
145
+    *)  SATURNIN_MENU_MNAME="$1"; shift; break ;;
146
+esac done
129
 
147
 
130
 load_parts
148
 load_parts
131
 
149