summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-04-21 00:04:49 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2020-04-21 00:04:49 -0400
commitdd61db791b0886fd103c917e2323ae27ae58423f (patch)
tree250274e804f8ce0abac4adcfaac4eaaf981a28aa
parent0ccde8ba416e36af2484276d9763a8742214528d (diff)
downloadcmd2-git-dd61db791b0886fd103c917e2323ae27ae58423f.tar.gz
run_pyscript now passes a keyword arg to do_py instead of using a hidden argparse flag
-rw-r--r--CHANGELOG.md4
-rw-r--r--cmd2/cmd2.py17
2 files changed, 11 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 01180001..03b88d03 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,7 +3,9 @@
* Made `ipy` consistent with `py` in the following ways
* `ipy` returns whether any of the commands run in it returned True to stop command loop
* `Cmd.in_pyscript()` returns True while in `ipy`.
- * Starting `ipy` when `Cmd.in_pyscript()` is already True is not allowed.
+ * Starting `ipy` when `Cmd.in_pyscript()` is already True is not allowed.
+ * `with_argument_list`, `with_argparser`, and `with_argparser_and_unknown_args` wrappers now pass
+ `kwargs` through to their wrapped command function.
## 1.0.2 (April 06, 2020)
* Bug Fixes
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 98969d10..34f53044 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -3169,17 +3169,16 @@ class Cmd(cmd.Cmd):
py_parser.add_argument('command', nargs=argparse.OPTIONAL, help="command to run")
py_parser.add_argument('remainder', nargs=argparse.REMAINDER, help="remainder of command")
- # This is a hidden flag for telling do_py to run a pyscript. It is intended only to be used by run_pyscript
- # after it sets up sys.argv for the script being run. When this flag is present, it takes precedence over all
- # other arguments.
- py_parser.add_argument('--pyscript', help=argparse.SUPPRESS)
-
# Preserve quotes since we are passing these strings to Python
@with_argparser(py_parser, preserve_quotes=True)
- def do_py(self, args: argparse.Namespace) -> Optional[bool]:
+ def do_py(self, args: argparse.Namespace, *, pyscript: Optional[str] = None) -> Optional[bool]:
"""
Enter an interactive Python shell
+ :param args: Namespace of args on the command line
+ :param pyscript: optional path to a pyscript file to run. This is intended only to be used by run_pyscript
+ after it sets up sys.argv for the script. If populated, this takes precedence over all
+ other arguments. (Defaults to None)
:return: True if running of commands should stop
"""
def py_quit():
@@ -3211,9 +3210,9 @@ class Cmd(cmd.Cmd):
localvars['self'] = self
# Handle case where we were called by run_pyscript
- if args.pyscript:
+ if pyscript is not None:
# Read the script file
- expanded_filename = os.path.expanduser(utils.strip_quotes(args.pyscript))
+ expanded_filename = os.path.expanduser(pyscript)
try:
with open(expanded_filename) as f:
@@ -3320,7 +3319,7 @@ class Cmd(cmd.Cmd):
sys.argv = [args.script_path] + args.script_arguments
# noinspection PyTypeChecker
- py_return = self.do_py('--pyscript {}'.format(utils.quote_string(args.script_path)))
+ py_return = self.do_py('', pyscript=args.script_path)
finally:
# Restore command line arguments to original state