Skip to content

Commit 10f365f

Browse files
authored
Merge pull request #128 from python-cmd2/use_arg_list
Changed default value of USE_ARG_LIST and bumped version
2 parents 056ea31 + b61268b commit 10f365f

File tree

7 files changed

+27
-18
lines changed

7 files changed

+27
-18
lines changed

CHANGES.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ News
77
*Release date: TBD*
88

99
* Bug fixes
10-
* Fixed a bug in display a span of history items when only an end index is supplied
10+
* Fixed a bug in displaying a span of history items when only an end index is supplied
1111
* Enhancements
1212
* Added the ability to exclude commands from the help menu (**eof** included by default)
13-
* Redundant list command removed and features merged into history command
14-
* Added **pyscript** command which supports running Python scripts with arguments
13+
* Redundant **list** command removed and features merged into **history** command
14+
* Added **pyscript** command which supports tab-completion and running Python scripts with arguments
15+
* Changed default value of USE_ARG_LIST to True - this affects the beavhior of all **@options** commands
16+
* **WARNING**: This breaks backwards compatibility, to restore backwards compatibility, add this to the
17+
**__init__()** method in your custom class derived from cmd2.Cmd:
18+
* set_use_arg_list(False)
19+
* This change improves argument parsing for all new applications
1520

1621
0.7.2
1722
-----

cmd2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
except ImportError:
8888
pass
8989

90-
__version__ = '0.7.3a'
90+
__version__ = '0.7.3'
9191

9292
# Pyparsing enablePackrat() can greatly speed up parsing, but problems have been seen in Python 3 in the past
9393
pyparsing.ParserElement.enablePackrat()
@@ -97,8 +97,8 @@
9797

9898

9999
# The next 3 variables and associated setter functions effect how arguments are parsed for commands using @options.
100-
# The defaults are "sane" and maximize backward compatibility with cmd and previous versions of cmd2.
101-
# But depending on your particular application, you may wish to tweak them so you get the desired parsing behavior.
100+
# The defaults are "sane" and maximize ease of use for new applications based on cmd2.
101+
# To maximize backwards compatibility, we recommend setting USE_ARG_LIST to "False"
102102

103103
# Use POSIX or Non-POSIX (Windows) rules for splitting a command-line string into a list of arguments via shlex.split()
104104
POSIX_SHLEX = False
@@ -107,7 +107,7 @@
107107
STRIP_QUOTES_FOR_NON_POSIX = True
108108

109109
# For option commands, pass a list of argument strings instead of a single argument string to the do_* methods
110-
USE_ARG_LIST = False
110+
USE_ARG_LIST = True
111111

112112

113113
def set_posix_shlex(val):

examples/example.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
verifying that the output produced matches the transcript.
1010
"""
1111

12-
from cmd2 import Cmd, make_option, options
12+
from cmd2 import Cmd, make_option, options, set_use_arg_list
1313

1414

1515
class CmdLineApp(Cmd):
@@ -26,6 +26,9 @@ def __init__(self):
2626
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
2727
Cmd.__init__(self, use_ipython=False)
2828

29+
# For option commands, pass a single argument string instead of a list of argument strings to the do_* methods
30+
set_use_arg_list(False)
31+
2932
@options([make_option('-p', '--piglatin', action="store_true", help="atinLay"),
3033
make_option('-s', '--shout', action="store_true", help="N00B EMULATION MODE"),
3134
make_option('-r', '--repeat', type="int", help="output [n] times")

examples/python_scripting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
from cmd2 import Cmd, options, make_option, CmdResult, set_use_arg_list
2121

22-
# For option commands, pass a list of argument strings instead of a single argument string to the do_* methods
23-
set_use_arg_list(True)
24-
2522

2623
class CmdLineApp(Cmd):
2724
""" Example cmd2 application to showcase conditional control flow in Python scripting within cmd2 aps. """
@@ -33,6 +30,9 @@ def __init__(self):
3330
self.autorun_on_edit = False
3431
self.intro = 'Happy 𝛑 Day. Note the full Unicode support: 😇 (Python 3 only) 💩'
3532

33+
# For option commands, pass a list of argument strings instead of a single argument string to the do_* methods
34+
set_use_arg_list(True)
35+
3636
def _set_prompt(self):
3737
"""Set prompt so it displays the current working directory."""
3838
self.cwd = os.getcwd()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66
from setuptools import setup
77

8-
VERSION = '0.7.3a'
8+
VERSION = '0.7.3'
99
DESCRIPTION = "Extra features for standard library's cmd module"
1010

1111
LONG_DESCRIPTION = """cmd2 is an enhancement to the standard library's cmd module for Python 2.7

tests/test_cmd2.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
def test_ver():
25-
assert cmd2.__version__ == '0.7.3a'
25+
assert cmd2.__version__ == '0.7.3'
2626

2727

2828
def test_base_help(base_app):
@@ -227,11 +227,11 @@ def test_base_cmdenvironment(base_app):
227227
Command-line arguments allowed: True
228228
Output redirection and pipes allowed: True
229229
Parsing of @options commands:
230-
Use POSIX-style argument parser (vs Windows): False
231-
Strip Quotes when using Windows-style argument parser: True
232-
Use a list of arguments instead of a single argument string: False
230+
Use POSIX-style argument parser (vs Windows): {}
231+
Strip Quotes when using Windows-style argument parser: {}
232+
Use a list of arguments instead of a single argument string: {}
233233
234-
""")
234+
""".format(cmd2.POSIX_SHLEX, cmd2.STRIP_QUOTES_FOR_NON_POSIX, cmd2.USE_ARG_LIST))
235235
assert out == expected
236236

237237
def test_base_load(base_app, request):

tests/test_transcript.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# Used for sm.input: raw_input() for Python 2 or input() for Python 3
1616
import six.moves as sm
1717

18-
from cmd2 import Cmd, make_option, options, Cmd2TestCase
18+
from cmd2 import Cmd, make_option, options, Cmd2TestCase, set_use_arg_list
1919
from conftest import run_cmd, StdOut, normalize
2020

2121

@@ -28,6 +28,7 @@ def __init__(self, *args, **kwargs):
2828
# Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x
2929
Cmd.__init__(self, *args, **kwargs)
3030
self.settable.append('maxrepeats Max number of `--repeat`s allowed')
31+
set_use_arg_list(False)
3132

3233
opts = [make_option('-p', '--piglatin', action="store_true", help="atinLay"),
3334
make_option('-s', '--shout', action="store_true", help="N00B EMULATION MODE"),

0 commit comments

Comments
 (0)