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

+ 4
- 0
tests/sfdoc/TF_RUN View File

@@ -18,6 +18,8 @@ tf_enum_subtests() {
18 18
     echo simplest
19 19
     echo simple
20 20
     echo tricky
21
+    echo simple_by_fun
22
+    echo simple_by_var
21 23
 }
22 24
 
23 25
 export SHELLFU_PATH=test/include
@@ -38,6 +40,8 @@ tf_do_subtest() {
38 40
         lsf_tricky)    cmd="sfdoc --lsfun test/include/tricky.sh" ;;
39 41
         direct_path)   cmd="sfdoc -e markdown test/other/path.sh" ;;
40 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 45
         *)             cmd="sfdoc -e markdown $name" ;;
42 46
     esac
43 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

@@ -0,0 +1 @@
1
+simple.stderr

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

@@ -0,0 +1 @@
1
+simple.stdout

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

@@ -0,0 +1 @@
1
+simple.stderr

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

@@ -0,0 +1 @@
1
+simple.stdout