summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2018-01-14 21:59:56 -0700
committerkotfu <kotfu@kotfu.net>2018-01-14 21:59:56 -0700
commitfda7300a6c3736ebe508490a88b35b7051e23f5e (patch)
tree1c652160da75a93fe13eec59a19501d14fa7c680 /cmd2.py
parent0e77f4bf8d8e0ff73f7ff118c3780306d5f47f87 (diff)
downloadcmd2-git-fda7300a6c3736ebe508490a88b35b7051e23f5e.tar.gz
convert do_show() to argparse
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/cmd2.py b/cmd2.py
index 045f1a39..0ecbc70b 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1289,17 +1289,14 @@ class Cmd(cmd.Cmd):
len(fulloptions)))
return result
- @options([make_option('-l', '--long', action="store_true", help="describe function of parameter")])
- def do_show(self, arg, opts):
- """Shows value of a parameter."""
- # If arguments are being passed as a list instead of as a string
- if USE_ARG_LIST:
- if arg:
- arg = arg[0]
- else:
- arg = ''
-
- param = arg.strip().lower()
+ argparser = argparse.ArgumentParser(description='show value of a parameter')
+ argparser.add_argument('-l', '--long', action='store_true', help='describe function of parameter')
+ argparser.add_argument('param', nargs='?', help='name of parameter, if not supplied show all parameters')
+ @with_argument_parser(argparser)
+ def do_show(self, arglist, args):
+ param = ''
+ if args.param:
+ param = args.param.strip().lower()
result = {}
maxlen = 0
for p in self.settable:
@@ -1308,7 +1305,7 @@ class Cmd(cmd.Cmd):
maxlen = max(maxlen, len(result[p]))
if result:
for p in sorted(result):
- if opts.long:
+ if args.long:
self.poutput('{} # {}'.format(result[p].ljust(maxlen), self.settable[p]))
else:
self.poutput(result[p])