diff options
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 35 |
1 files changed, 14 insertions, 21 deletions
@@ -1292,17 +1292,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: @@ -1311,7 +1308,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]) @@ -1615,32 +1612,28 @@ class Cmd(cmd.Cmd): self._in_py = False return self._should_quit - # noinspection PyUnusedLocal - @options([], arg_desc='<script_path> [script_arguments]') - def do_pyscript(self, arg, opts=None): + @with_argument_list + def do_pyscript(self, arglist): """\nRuns a python script file inside the console Console commands can be executed inside this script with cmd("your command") However, you cannot run nested "py" or "pyscript" commands from within this script Paths or arguments that contain spaces must be enclosed in quotes """ - if not arg: + if not arglist: self.perror("pyscript command requires at least 1 argument ...", traceback_war=False) self.do_help('pyscript') return - if not USE_ARG_LIST: - arg = shlex.split(arg, posix=POSIX_SHLEX) - # Get the absolute path of the script - script_path = os.path.expanduser(arg[0]) + script_path = os.path.expanduser(arglist[0]) # Save current command line arguments orig_args = sys.argv # Overwrite sys.argv to allow the script to take command line arguments sys.argv = [script_path] - sys.argv.extend(arg[1:]) + sys.argv.extend(arglist[1:]) # Run the script - use repr formatting to escape things which need to be escaped to prevent issues on Windows self.do_py("run({!r})".format(script_path)) |