This is an automated email from the ASF dual-hosted git repository.

aw pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/yetus.git


The following commit(s) were added to refs/heads/main by this push:
     new aa0f2a3  YETUS-1089. replaceable is not consistently handled (#208)
aa0f2a3 is described below

commit aa0f2a380002457b544472988cd046b3ae8cd903
Author: Allen Wittenauer <[email protected]>
AuthorDate: Fri Nov 27 07:29:08 2020 -0800

    YETUS-1089. replaceable is not consistently handled (#208)
    
    * turn replaceb into a bool so that it always has a value
    * make the lint actually check the text not what the template table
      looks like
    * fix the condition where the output file doesn't have a directory
    
    Signed-off-by: Sean Busbey <[email protected]>
---
 shelldocs/src/main/python/shelldocs.py | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/shelldocs/src/main/python/shelldocs.py 
b/shelldocs/src/main/python/shelldocs.py
index c953d1f..c9e7d9c 100755
--- a/shelldocs/src/main/python/shelldocs.py
+++ b/shelldocs/src/main/python/shelldocs.py
@@ -78,7 +78,8 @@ class ShellFunction:  # pylint: 
disable=too-many-public-methods, too-many-instan
         self.name = None
         self.audience = None
         self.stability = None
-        self.replaceb = None
+        self.replacetext = None
+        self.replaceb = False
         self.returnt = None
         self.desc = None
         self.params = None
@@ -91,7 +92,7 @@ class ShellFunction:  # pylint: 
disable=too-many-public-methods, too-many-instan
             if self.stability == other.stability:
                 if self.replaceb == other.replaceb:
                     return self.name < other.name
-                if self.replaceb == "Yes":
+                if self.replaceb:
                     return True
             else:
                 if self.stability == "Stable":
@@ -106,7 +107,8 @@ class ShellFunction:  # pylint: 
disable=too-many-public-methods, too-many-instan
         self.name = None
         self.audience = None
         self.stability = None
-        self.replaceb = None
+        self.replacetext = None
+        self.replaceb = False
         self.returnt = None
         self.desc = None
         self.params = None
@@ -165,13 +167,14 @@ class ShellFunction:  # pylint: 
disable=too-many-public-methods, too-many-instan
 
     def setreplace(self, text):
         '''set the replacement state'''
-        self.replaceb = docstrip("replaceable", text)
-        self.replaceb = self.replaceb.capitalize()
+        self.replacetext = docstrip("replaceable", text)
+        if self.replacetext.capitalize() == "Yes":
+            self.replaceb = True
 
     def getreplace(self):
         '''get the replacement state'''
-        if self.replaceb == "Yes":
-            return self.replaceb
+        if self.replaceb:
+            return "Yes"
         return "No"
 
     def getinter(self):
@@ -258,17 +261,17 @@ class ShellFunction:  # pylint: 
disable=too-many-public-methods, too-many-instan
         getfuncs = {
             "audience": self.getaudience,
             "stability": self.getstability,
-            "replaceable": self.getreplace,
+            "replaceable": self.replacetext,
         }
         validvalues = {
             "audience": ("Public", "Private"),
             "stability": ("Stable", "Evolving"),
-            "replaceable": ("Yes", "No"),
+            "replaceable": ("yes", "no"),
         }
         messages = []
         for attr in ("audience", "stability", "replaceable"):
             value = getfuncs[attr]()
-            if value == "None":
+            if value == "None" and attr != 'replaceable':
                 messages.append("%s:%u: ERROR: function %s has no @%s" %
                                 (self.getfilename(), self.getlinenum(),
                                  self.getname(), attr.lower()))
@@ -381,8 +384,9 @@ def write_output(filename, functions):
     """ write the markdown file """
     try:
         directory = os.path.dirname(filename)
-        if not os.path.exists(directory):
-            os.makedirs(directory)
+        if directory:
+            if not os.path.exists(directory):
+                os.makedirs(directory)
     except OSError as exc:
         if exc.errno == errno.EEXIST and os.path.isdir(directory):
             pass
@@ -411,7 +415,7 @@ def main():
     parser = ArgumentParser(
         prog='shelldocs',
         epilog="You can mark a file to be ignored by shelldocs by adding"
-        " 'SHELLDOC-IGNORE' as comment in its own line. "+
+        " 'SHELLDOC-IGNORE' as comment in its own line. " +
         "--input may be given multiple times.")
     parser.add_argument("-o",
                         "--output",

Reply via email to