summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2018-01-14 22:27:43 -0700
committerkotfu <kotfu@kotfu.net>2018-01-14 22:27:43 -0700
commit6454f4e3ba61bdac9cdd09528d58261ecb235b5e (patch)
treee1c1abb2ea8561dc79fb8bc1799c4fc00352785d /cmd2.py
parentfda7300a6c3736ebe508490a88b35b7051e23f5e (diff)
downloadcmd2-git-6454f4e3ba61bdac9cdd09528d58261ecb235b5e.tar.gz
convert do_pyscript() to use @with_argument_list
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/cmd2.py b/cmd2.py
index 0ecbc70b..3d11e252 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1609,32 +1609,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))