You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@yetus.apache.org by aw...@apache.org on 2019/05/21 02:15:06 UTC
[yetus] branch master updated: YETUS-885. Support more function
formats in shelldocs (#58)
This is an automated email from the ASF dual-hosted git repository.
aw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yetus.git
The following commit(s) were added to refs/heads/master by this push:
new ae2c5d8 YETUS-885. Support more function formats in shelldocs (#58)
ae2c5d8 is described below
commit ae2c5d83b4f10cc90d60091db24469a29b5bf476
Author: Allen Wittenauer <aw...@apache.org>
AuthorDate: Mon May 20 19:15:00 2019 -0700
YETUS-885. Support more function formats in shelldocs (#58)
---
.../source/documentation/in-progress/shelldocs.md | 38 ++++++++++++++++++++--
shelldocs/src/main/python/shelldocs/__init__.py | 11 +++++--
2 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/asf-site-src/source/documentation/in-progress/shelldocs.md b/asf-site-src/source/documentation/in-progress/shelldocs.md
index 56db17b..931a6cd 100644
--- a/asf-site-src/source/documentation/in-progress/shelldocs.md
+++ b/asf-site-src/source/documentation/in-progress/shelldocs.md
@@ -45,7 +45,7 @@ Some projects have complex shell functions that act as APIs. `shelldocs` provide
# Function Annotations
-`shelldocs` works by doing simple parsing of shell scripts. As such, it looks for code that matches this pattern:
+`shelldocs` works by doing simple parsing of shell scripts. As such, it looks for code that matches these patterns:
```bash
## @annotation
@@ -54,7 +54,41 @@ function functioname() {
}
```
-This is Korn shell syntax that other shell languages (such as bash) will correctly interpret as a function.
+```bash
+## @annotation
+function functioname () {
+ ...
+}
+```
+
+```bash
+## @annotation
+function functioname {
+ ...
+}
+```
+
+```bash
+## @annotation
+function functioname
+{
+ ...
+}
+```
+
+```bash
+## @annotation
+functioname() {
+ ...
+}
+```
+
+```bash
+## @annotation
+functioname () {
+ ...
+}
+```
Note that the comment has two hash ('#') marks. The content of the comment is key. This is what `shelldocs` will turn into documentation. The following annotations are supported:
diff --git a/shelldocs/src/main/python/shelldocs/__init__.py b/shelldocs/src/main/python/shelldocs/__init__.py
index 765fd5e..29ed858 100755
--- a/shelldocs/src/main/python/shelldocs/__init__.py
+++ b/shelldocs/src/main/python/shelldocs/__init__.py
@@ -46,6 +46,8 @@ ASFLICENSE = '''
-->
'''
+FUNCTIONRE = re.compile(r"^(\w+) *\(\) *{")
+
def docstrip(key, dstr):
'''remove extra spaces from shelldoc phrase'''
@@ -122,8 +124,11 @@ class ShellFunction(object): # pylint: disable=too-many-public-methods, too-many
def setname(self, text):
'''set the name of the function'''
- definition = text.split()
- self.name = definition[1]
+ if FUNCTIONRE.match(text):
+ definition = FUNCTIONRE.match(text).groups()[0]
+ else:
+ definition = text.split()[1]
+ self.name = definition.replace("(", "").replace(")", "")
def getname(self):
'''get the name of the function'''
@@ -331,7 +336,7 @@ def process_file(filename, skipprnorep):
funcdef.addparam(line)
elif line.startswith('## @return'):
funcdef.addreturn(line)
- elif line.startswith('function'):
+ elif line.startswith('function') or FUNCTIONRE.match(line):
funcdef.setname(line)
funcdef.setlinenum(linenum)
if skipprnorep and \