diff options
author | kotfu <kotfu@kotfu.net> | 2018-01-14 21:59:56 -0700 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2018-01-14 21:59:56 -0700 |
commit | fda7300a6c3736ebe508490a88b35b7051e23f5e (patch) | |
tree | 1c652160da75a93fe13eec59a19501d14fa7c680 /cmd2.py | |
parent | 0e77f4bf8d8e0ff73f7ff118c3780306d5f47f87 (diff) | |
download | cmd2-git-fda7300a6c3736ebe508490a88b35b7051e23f5e.tar.gz |
convert do_show() to argparse
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 21 |
1 files changed, 9 insertions, 12 deletions
@@ -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]) |