Browse Source

Allow specifying function or variable name instead of MODULE

Alois Mahdal 6 years ago
parent
commit
efcf435161

+ 25
- 4
src/bin/sfdoc View File

28
             "                   format FMT: 'markdown', 'manpage' and"  \
28
             "                   format FMT: 'markdown', 'manpage' and"  \
29
             "                   'pod' are supported"                    \
29
             "                   'pod' are supported"                    \
30
         -o                                                              \
30
         -o                                                              \
31
+            "-O, --object       Treat MODULE as function or variable"   \
32
+            "                   name and find respective module first." \
31
             "-d, --debug        Turn on debugging"                      \
33
             "-d, --debug        Turn on debugging"                      \
32
             "-a, --all          Don't ignore hidden (starting with"     \
34
             "-a, --all          Don't ignore hidden (starting with"     \
33
             "                   underscore) modules or objects"         \
35
             "                   underscore) modules or objects"         \
71
      2>/dev/null
73
      2>/dev/null
72
 }
74
 }
73
 
75
 
76
+find_by() {
77
+    #
78
+    # Find module by object type $1 and name $2
79
+    #
80
+    local name=$1
81
+    sfdoc -a -l \
82
+      | grep ":$name$" \
83
+      | cut -d: -f1 \
84
+      | grep .
85
+}
86
+
74
 main() {
87
 main() {
75
     local action            # what to do
88
     local action            # what to do
76
     local format            # export format
89
     local format            # export format
77
     local module            # module name or path/to/module.sh
90
     local module            # module name or path/to/module.sh
91
+    local mspec             # module/function name or path/to/module.sh
78
     local m                 # module helper var
92
     local m                 # module helper var
79
     local RealModuleName    # name to override eg. if accessing via filename
93
     local RealModuleName    # name to override eg. if accessing via filename
80
     local encoding          # encoding
94
     local encoding          # encoding
82
     action=man
96
     action=man
83
     format=markdown
97
     format=markdown
84
     encoding=utf8
98
     encoding=utf8
99
+    spectype=mod
85
     #shellcheck disable=SC2034
100
     #shellcheck disable=SC2034
86
     while true; do case "$1" in
101
     while true; do case "$1" in
102
+        -O|--object)    spectype=obj;               shift ;;
87
         -d|--debug)     PRETTY_DEBUG=true;          shift ;;
103
         -d|--debug)     PRETTY_DEBUG=true;          shift ;;
88
         -a|--all)       SFDOC_SHOW_HIDDEN=true;     shift ;;
104
         -a|--all)       SFDOC_SHOW_HIDDEN=true;     shift ;;
89
         -I|--include)   SHELLFU_PATH="$2:$SHELLFU_PATH"; shift 2 || usage ;;
105
         -I|--include)   SHELLFU_PATH="$2:$SHELLFU_PATH"; shift 2 || usage ;;
100
         -*)                                         usage ;;
116
         -*)                                         usage ;;
101
         *)                                          break ;;
117
         *)                                          break ;;
102
     esac done
118
     esac done
103
-    module="$1"; shift
119
+    mspec="$1"; shift
104
     debug -v SHELLFU_INCLUDE SHELLFU_PATH SFDOC_SHOW_HIDDEN
120
     debug -v SHELLFU_INCLUDE SHELLFU_PATH SFDOC_SHOW_HIDDEN
105
     debug -v action format module RealModuleName
121
     debug -v action format module RealModuleName
106
-    case $action:$module in
122
+    case $action:$mspec in
107
         lsx:*|lsm:*|wch:*) true ;;
123
         lsx:*|lsm:*|wch:*) true ;;
108
         *:)             usage ;;
124
         *:)             usage ;;
109
     esac
125
     esac
126
+    case $spectype in
127
+        obj) module=$(find_by "$mspec") \
128
+              || die "no module found with: $mspec" ;;
129
+        *)   module=$mspec ;;
130
+    esac
110
     case $action in
131
     case $action in
111
-        lsm|wch) : ;;
132
+        lsm)    : ;;
112
         *)      mpath=$(select_mfile "$module") || die ;;
133
         *)      mpath=$(select_mfile "$module") || die ;;
113
     esac
134
     esac
114
     case $action in
135
     case $action in
159
             fi
180
             fi
160
             ;;
181
             ;;
161
         wch)
182
         wch)
162
-            select_mfile "$module"
183
+            echo "$mpath"
163
             ;;
184
             ;;
164
     esac
185
     esac
165
 }
186
 }

+ 4
- 0
tests/sfdoc/TF_RUN View File

18
     echo simplest
18
     echo simplest
19
     echo simple
19
     echo simple
20
     echo tricky
20
     echo tricky
21
+    echo simple_by_fun
22
+    echo simple_by_var
21
 }
23
 }
22
 
24
 
23
 export SHELLFU_PATH=test/include
25
 export SHELLFU_PATH=test/include
38
         lsf_tricky)    cmd="sfdoc --lsfun test/include/tricky.sh" ;;
40
         lsf_tricky)    cmd="sfdoc --lsfun test/include/tricky.sh" ;;
39
         direct_path)   cmd="sfdoc -e markdown test/other/path.sh" ;;
41
         direct_path)   cmd="sfdoc -e markdown test/other/path.sh" ;;
40
         included_path) cmd="sfdoc -I test/other -e markdown path" ;;
42
         included_path) cmd="sfdoc -I test/other -e markdown path" ;;
43
+        simple_by_fun) cmd="sfdoc -O -e markdown simple_foo" ;;
44
+        simple_by_var) cmd="sfdoc -O -e markdown SIMPLE_LIMIT" ;;
41
         *)             cmd="sfdoc -e markdown $name" ;;
45
         *)             cmd="sfdoc -e markdown $name" ;;
42
     esac
46
     esac
43
     tf_testflt -n "$name" -O "oracle/$name.stdout" -E "oracle/$name.stderr" -S "$o_es" "$cmd"
47
     tf_testflt -n "$name" -O "oracle/$name.stdout" -E "oracle/$name.stderr" -S "$o_es" "$cmd"

+ 1
- 0
tests/sfdoc/oracle/simple_by_fun.stderr View File

1
+simple.stderr

+ 1
- 0
tests/sfdoc/oracle/simple_by_fun.stdout View File

1
+simple.stdout

+ 1
- 0
tests/sfdoc/oracle/simple_by_var.stderr View File

1
+simple.stderr

+ 1
- 0
tests/sfdoc/oracle/simple_by_var.stdout View File

1
+simple.stdout