summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2022-02-24 10:11:40 +0100
committerJose M. Guisado Gomez <guigom@riseup.net>2022-05-10 16:19:17 +0200
commit5c1137662e3f5c6c0793b038944853b43c391239 (patch)
tree2f3d05e4015d9a761d72938a25b0c9db3ea33bc3
parent0f2d1f1dba4a91ef7c0c7104e1995ae8d2cba576 (diff)
Fix --help
Non-method attributes are shown using dir() when listing available commands. usage: ogcli [-h] [{create,list,restore,rest,send,set,setup}] 'rest' is a class instance of OgRest and must not be shown when listing available commands. Method members of OgCLI class are the available commands that ogcli can execute. Use inspect module in order to get class members (getmembers) and filter only those that are a method (ismethod). usage: ogcli [-h] [{create,list,restore,send,set,setup}] Fixes: 0f2d1f1dba4 ("Show all valid commands when running ogcli --help")
-rwxr-xr-xogcli8
1 files changed, 5 insertions, 3 deletions
diff --git a/ogcli b/ogcli
index abea632..4cfe339 100755
--- a/ogcli
+++ b/ogcli
@@ -7,6 +7,8 @@
# Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
+from inspect import ismethod, getmembers
+
from cli.cli import OgCLI
import argparse
import json
@@ -34,9 +36,9 @@ class CLI():
self.ogcli = OgCLI(self.cfg)
parser = argparse.ArgumentParser(prog='ogcli')
- parser.add_argument('command', help='Subcommand to run',
- choices=[attr for attr in dir(self.ogcli)
- if not str.startswith(attr, "_")])
+ parser.add_argument('command', help='Subcommand to run', nargs='?',
+ choices=[attr for attr, _ in getmembers(self.ogcli, lambda x: ismethod(x))
+ if not attr.startswith('_')])
args = parser.parse_args(sys.argv[1:2])
if not hasattr(self.ogcli, args.command):