summaryrefslogtreecommitdiff
path: root/examples/python_scripting.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-01-15 02:03:00 -0500
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-01-15 02:03:00 -0500
commitb4e6fc40b0af32aabed00635a6402d18620760c2 (patch)
treeb2deca0068d628612022f1cabace8e5fcee14a13 /examples/python_scripting.py
parentcb412f66596cb5ba2ac3e5d45727ffc74fbf4db0 (diff)
downloadcmd2-git-b4e6fc40b0af32aabed00635a6402d18620760c2.tar.gz
Modified examples still using @options to import make_option from optparse
Diffstat (limited to 'examples/python_scripting.py')
-rwxr-xr-xexamples/python_scripting.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/examples/python_scripting.py b/examples/python_scripting.py
index ae04fda1..68290a7b 100755
--- a/examples/python_scripting.py
+++ b/examples/python_scripting.py
@@ -17,7 +17,8 @@ This application and the "scripts/conditional.py" script serve as an example for
import functools
import os
-from cmd2 import Cmd, options, make_option, CmdResult, set_use_arg_list
+from cmd2 import Cmd, options, CmdResult, with_argument_list
+from optparse import make_option
class CmdLineApp(Cmd):
@@ -30,9 +31,6 @@ 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()
@@ -49,19 +47,21 @@ class CmdLineApp(Cmd):
self._set_prompt()
return stop
- # noinspection PyUnusedLocal
- @options([], arg_desc='<new_dir>')
- def do_cd(self, arg, opts=None):
- """Change directory."""
+ @with_argument_list
+ def do_cd(self, arglist):
+ """Change directory.
+ Usage:
+ cd <new_dir>
+ """
# Expect 1 argument, the directory to change to
- if not arg or len(arg) != 1:
+ if not arglist or len(arglist) != 1:
self.perror("cd requires exactly 1 argument:", traceback_war=False)
self.do_help('cd')
self._last_result = CmdResult('', 'Bad arguments')
return
# Convert relative paths to absolute paths
- path = os.path.abspath(os.path.expanduser(arg[0]))
+ path = os.path.abspath(os.path.expanduser(arglist[0]))
# Make sure the directory exists, is a directory, and we have read access
out = ''