summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-06-14 21:37:38 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-06-14 21:37:38 -0400
commitf2cb3a009456ec9115e41720e81ef031ed4eaf46 (patch)
treef72647fe6918977fe038725e40e3b6e172874943 /examples
parent056ea31581af194971816f4150e4f8c2aa7b000c (diff)
downloadcmd2-git-f2cb3a009456ec9115e41720e81ef031ed4eaf46.tar.gz
Changed default value for USE_ARG_LIST global to True
Now by default all @options commands get passed a list of argument strings instead of a single argument string. This is a much easier and more robust behavior to deal with. Additionally, command-line arguments are intelligently separated based on location of quotes to group things into a single argument. WARNING: This change breaks backward compatibility for older applicaitons based on cmd2. To change the behavior to the way it used to be, add the following code to the __init__() method of our class derived from cmd2.Cmd: cmd2.set_use_arg_list(False) This change really does make it easier for developers new to using cmd2 however. It is to the point where I create all custom commands with @options, even if I use an empty list for the options because the argument parsing is just much better this way.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/example.py5
-rwxr-xr-xexamples/python_scripting.py6
2 files changed, 7 insertions, 4 deletions
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()