]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind/ceph_argparse: adjust help text for non-positional args
authorSage Weil <sage@newdream.net>
Fri, 21 May 2021 22:01:03 +0000 (18:01 -0400)
committerSage Weil <sage@newdream.net>
Tue, 1 Jun 2021 18:39:52 +0000 (14:39 -0400)
If an arg is non-positional, always show it as

  [--arg-name <value>]

(All non-positional args are optional.)

Signed-off-by: Sage Weil <sage@newdream.net>
src/pybind/ceph_argparse.py

index 77e31e228602d501f73d63a463d9585a6d07687c..c5b813ddcaa970beaee284ac82524304e268f2ac 100644 (file)
@@ -836,34 +836,61 @@ class argdesc(object):
         like str(), but omit parameter names (except for CephString,
         which really needs them)
         """
-        if self.t == CephBool:
-            chunk = "--{0}".format(self.name.replace("_", "-"))
-        elif self.t == CephPrefix:
-            chunk = str(self.instance)
-        elif self.t == CephChoices:
-            if self.name == 'format':
-                chunk = f'--{self.name} {{{str(self.instance)}}}'
-            else:
+        if self.positional:
+            if self.t == CephBool:
+                chunk = "--{0}".format(self.name.replace("_", "-"))
+            elif self.t == CephPrefix:
                 chunk = str(self.instance)
-        elif self.t == CephOsdName:
-            # it just so happens all CephOsdName commands are named 'id' anyway,
-            # so <id|osd.id> is perfect.
-            chunk = '<id|osd.id>'
-        elif self.t == CephName:
-            # CephName commands similarly only have one arg of the
-            # type, so <type.id> is good.
-            chunk = '<type.id>'
-        elif self.t == CephInt:
-            chunk = '<{0}:int>'.format(self.name)
-        elif self.t == CephFloat:
-            chunk = '<{0}:float>'.format(self.name)
+            elif self.t == CephChoices:
+                if self.name == 'format':
+                    # this is for talking to legacy clusters only; new clusters
+                    # should properly mark format args as non-positional.
+                    chunk = f'--{self.name} {{{str(self.instance)}}}'
+                else:
+                    chunk = f'<{self.name}:{self.instance}>'
+            elif self.t == CephOsdName:
+                # it just so happens all CephOsdName commands are named 'id' anyway,
+                # so <id|osd.id> is perfect.
+                chunk = '<id|osd.id>'
+            elif self.t == CephName:
+                # CephName commands similarly only have one arg of the
+                # type, so <type.id> is good.
+                chunk = '<type.id>'
+            elif self.t == CephInt:
+                chunk = '<{0}:int>'.format(self.name)
+            elif self.t == CephFloat:
+                chunk = '<{0}:float>'.format(self.name)
+            else:
+                chunk = '<{0}>'.format(self.name)
+            s = chunk
+            if self.N:
+                s += '...'
+            if not self.req:
+                s = '[' + s + ']'
         else:
-            chunk = '<{0}>'.format(self.name)
-        s = chunk
-        if self.N:
-            s += '...'
-        if not self.req:
-            s = '[' + s + ']'
+            # non-positional
+            if self.t == CephBool:
+                chunk = "--{0}".format(self.name.replace("_", "-"))
+            elif self.t == CephPrefix:
+                chunk = str(self.instance)
+            elif self.t == CephChoices:
+                chunk = f'--{self.name} {{{str(self.instance)}}}'
+            elif self.t == CephOsdName:
+                chunk = f'--{self.name} <id|osd.id>'
+            elif self.t == CephName:
+                chunk = f'--{self.name} <type.id>'
+            elif self.t == CephInt:
+                chunk = f'--{self.name} <int>'
+            elif self.t == CephFloat:
+                chunk = f'--{self.name} <float>'
+            else:
+                chunk = f'--{self.name} <value>'
+            s = chunk
+            if self.N:
+                s += '...'
+            if not self.req:  # req should *always* be false
+                s = '[' + s + ']'
+
         return s
 
     def complete(self, s):