Browse Source

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 9 years ago
parent
commit
256d6f51f7
1 changed files with 31 additions and 13 deletions
  1. 31
    13
      src/libexec/saturnin-menu

+ 31
- 13
src/libexec/saturnin-menu View File

@@ -6,7 +6,7 @@ ffoo import inigrep
6 6
 ffoo import pretty
7 7
 
8 8
 usage() {
9
-    mkusage "[name]"
9
+    mkusage "[-g generator_cmd] [-s selector_cmd] [-c consumer_cmd] [name]"
10 10
 }
11 11
 
12 12
 SATURNIN_MENU_MNAME=""
@@ -17,29 +17,40 @@ SATURNIN_MENU_CONSUMER=""
17 17
 
18 18
 load_parts() {
19 19
     #
20
-    # Load mandatory parts
20
+    # Load mandatory parts for menu name $1
21 21
     #
22 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 31
     inigrep -s menu.$mname | grep -q . \
25 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 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 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 47
      || die "cannot find consumer for menu: $mname"
33 48
 }
34 49
 
35 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 54
     inigrep -1 -p menu._default_.name | grep .
44 55
 }
45 56
 
@@ -125,7 +136,14 @@ do_consume() {
125 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 148
 load_parts
131 149