From b9a2a71402921df762a828373d99761c28e5320e Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 21 May 2021 18:01:03 -0400 Subject: [PATCH] pybind/ceph_argparse: adjust help text for non-positional args If an arg is non-positional, always show it as [--arg-name ] (All non-positional args are optional.) Signed-off-by: Sage Weil --- src/pybind/ceph_argparse.py | 79 +++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/src/pybind/ceph_argparse.py b/src/pybind/ceph_argparse.py index 77e31e22860..c5b813ddcaa 100644 --- a/src/pybind/ceph_argparse.py +++ b/src/pybind/ceph_argparse.py @@ -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 is perfect. - chunk = '' - elif self.t == CephName: - # CephName commands similarly only have one arg of the - # type, so is good. - chunk = '' - 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 is perfect. + chunk = '' + elif self.t == CephName: + # CephName commands similarly only have one arg of the + # type, so is good. + chunk = '' + 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} ' + elif self.t == CephName: + chunk = f'--{self.name} ' + elif self.t == CephInt: + chunk = f'--{self.name} ' + elif self.t == CephFloat: + chunk = f'--{self.name} ' + else: + chunk = f'--{self.name} ' + s = chunk + if self.N: + s += '...' + if not self.req: # req should *always* be false + s = '[' + s + ']' + return s def complete(self, s): -- 2.39.5