diff options
-rwxr-xr-x | cmd2.py | 6 | ||||
-rwxr-xr-x | examples/example.py | 5 | ||||
-rwxr-xr-x | examples/python_scripting.py | 6 | ||||
-rw-r--r-- | tests/test_cmd2.py | 8 | ||||
-rw-r--r-- | tests/test_transcript.py | 3 |
5 files changed, 16 insertions, 12 deletions
@@ -97,8 +97,8 @@ pyparsing.ParserElement.setDefaultWhitespaceChars(' \t') # The next 3 variables and associated setter functions effect how arguments are parsed for commands using @options. -# The defaults are "sane" and maximize backward compatibility with cmd and previous versions of cmd2. -# But depending on your particular application, you may wish to tweak them so you get the desired parsing behavior. +# The defaults are "sane" and maximize ease of use for new applications based on cmd2. +# To maximize backwards compatibility, we recommend setting USE_ARG_LIST to "False" # Use POSIX or Non-POSIX (Windows) rules for splitting a command-line string into a list of arguments via shlex.split() POSIX_SHLEX = False @@ -107,7 +107,7 @@ POSIX_SHLEX = False STRIP_QUOTES_FOR_NON_POSIX = True # For option commands, pass a list of argument strings instead of a single argument string to the do_* methods -USE_ARG_LIST = False +USE_ARG_LIST = True def set_posix_shlex(val): diff --git a/examples/example.py b/examples/example.py index cb4aba04..68e08890 100755 --- a/examples/example.py +++ b/examples/example.py @@ -9,7 +9,7 @@ Running `python example.py -t exampleSession.txt` will run all the commands in t verifying that the output produced matches the transcript. """ -from cmd2 import Cmd, make_option, options +from cmd2 import Cmd, make_option, options, set_use_arg_list class CmdLineApp(Cmd): @@ -26,6 +26,9 @@ class CmdLineApp(Cmd): # Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell Cmd.__init__(self, use_ipython=False) + # For option commands, pass a single argument string instead of a list of argument strings to the do_* methods + set_use_arg_list(False) + @options([make_option('-p', '--piglatin', action="store_true", help="atinLay"), make_option('-s', '--shout', action="store_true", help="N00B EMULATION MODE"), make_option('-r', '--repeat', type="int", help="output [n] times") diff --git a/examples/python_scripting.py b/examples/python_scripting.py index 6c64dd9f..716a18a3 100755 --- a/examples/python_scripting.py +++ b/examples/python_scripting.py @@ -19,9 +19,6 @@ import os from cmd2 import Cmd, options, make_option, CmdResult, set_use_arg_list -# For option commands, pass a list of argument strings instead of a single argument string to the do_* methods -set_use_arg_list(True) - class CmdLineApp(Cmd): """ Example cmd2 application to showcase conditional control flow in Python scripting within cmd2 aps. """ @@ -33,6 +30,9 @@ class CmdLineApp(Cmd): self.autorun_on_edit = False self.intro = 'Happy 𝛑 Day. Note the full Unicode support: 😇 (Python 3 only) 💩' + # For option commands, pass a list of argument strings instead of a single argument string to the do_* methods + set_use_arg_list(True) + def _set_prompt(self): """Set prompt so it displays the current working directory.""" self.cwd = os.getcwd() diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 2198d5c0..3a69c09c 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -227,11 +227,11 @@ def test_base_cmdenvironment(base_app): Command-line arguments allowed: True Output redirection and pipes allowed: True Parsing of @options commands: - Use POSIX-style argument parser (vs Windows): False - Strip Quotes when using Windows-style argument parser: True - Use a list of arguments instead of a single argument string: False + Use POSIX-style argument parser (vs Windows): {} + Strip Quotes when using Windows-style argument parser: {} + Use a list of arguments instead of a single argument string: {} -""") +""".format(cmd2.POSIX_SHLEX, cmd2.STRIP_QUOTES_FOR_NON_POSIX, cmd2.USE_ARG_LIST)) assert out == expected def test_base_load(base_app, request): diff --git a/tests/test_transcript.py b/tests/test_transcript.py index 5ac7d6fd..4a7d57a6 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -15,7 +15,7 @@ import six # Used for sm.input: raw_input() for Python 2 or input() for Python 3 import six.moves as sm -from cmd2 import Cmd, make_option, options, Cmd2TestCase +from cmd2 import Cmd, make_option, options, Cmd2TestCase, set_use_arg_list from conftest import run_cmd, StdOut, normalize @@ -28,6 +28,7 @@ class CmdLineApp(Cmd): # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x Cmd.__init__(self, *args, **kwargs) self.settable.append('maxrepeats Max number of `--repeat`s allowed') + set_use_arg_list(False) opts = [make_option('-p', '--piglatin', action="store_true", help="atinLay"), make_option('-s', '--shout', action="store_true", help="N00B EMULATION MODE"), |