summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-06-25 14:05:20 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-06-25 14:05:20 -0400
commit36c310f9311bc9a48428950a9532934ffc3f45f2 (patch)
treebca883bb615f421e7b53e41f915723a76fd818e3
parent87cd9aba00dde219a7b2e5e7d9fdd1c1a73c287a (diff)
downloadcmd2-git-36c310f9311bc9a48428950a9532934ffc3f45f2.tar.gz
Replaced more pexcept uses with perror
-rw-r--r--docs/argument_processing.rst2
-rwxr-xr-xexamples/paged_output.py10
-rwxr-xr-xexamples/python_scripting.py6
-rw-r--r--tests/test_cmd2.py6
4 files changed, 12 insertions, 12 deletions
diff --git a/docs/argument_processing.rst b/docs/argument_processing.rst
index 599e4cf0..a1fc107b 100644
--- a/docs/argument_processing.rst
+++ b/docs/argument_processing.rst
@@ -265,7 +265,7 @@ Here's what it looks like::
"""List contents of current directory."""
# No arguments for this command
if unknown:
- self.perror("dir does not take any positional arguments:", traceback_war=False)
+ self.perror("dir does not take any positional arguments:")
self.do_help('dir')
self.last_result = CommandResult('', 'Bad arguments')
return
diff --git a/examples/paged_output.py b/examples/paged_output.py
index 4986168b..cba5c7c5 100755
--- a/examples/paged_output.py
+++ b/examples/paged_output.py
@@ -14,15 +14,15 @@ class PagedOutput(cmd2.Cmd):
def __init__(self):
super().__init__()
- def page_file(self, file_path: str, chop: bool=False):
+ def page_file(self, file_path: str, chop: bool = False):
"""Helper method to prevent having too much duplicated code."""
filename = os.path.expanduser(file_path)
try:
with open(filename, 'r') as f:
text = f.read()
self.ppaged(text, chop=chop)
- except FileNotFoundError:
- self.pexcept('ERROR: file {!r} not found'.format(filename), traceback_war=False)
+ except OSError as ex:
+ self.pexcept('Error reading {!r}: {}'.format(filename, ex))
@cmd2.with_argument_list
def do_page_wrap(self, args: List[str]):
@@ -31,7 +31,7 @@ class PagedOutput(cmd2.Cmd):
Usage: page_wrap <file_path>
"""
if not args:
- self.pexcept('page_wrap requires a path to a file as an argument', traceback_war=False)
+ self.perror('page_wrap requires a path to a file as an argument')
return
self.page_file(args[0], chop=False)
@@ -46,7 +46,7 @@ class PagedOutput(cmd2.Cmd):
Usage: page_chop <file_path>
"""
if not args:
- self.pexcept('page_truncate requires a path to a file as an argument', traceback_war=False)
+ self.perror('page_truncate requires a path to a file as an argument')
return
self.page_file(args[0], chop=True)
diff --git a/examples/python_scripting.py b/examples/python_scripting.py
index f9461fa5..0cbfddff 100755
--- a/examples/python_scripting.py
+++ b/examples/python_scripting.py
@@ -56,7 +56,7 @@ class CmdLineApp(cmd2.Cmd):
"""
# Expect 1 argument, the directory to change to
if not arglist or len(arglist) != 1:
- self.pexcept("cd requires exactly 1 argument:", traceback_war=False)
+ self.perror("cd requires exactly 1 argument:")
self.do_help('cd')
self.last_result = cmd2.CommandResult('', 'Bad arguments')
return
@@ -83,7 +83,7 @@ class CmdLineApp(cmd2.Cmd):
data = path
if err:
- self.pexcept(err, traceback_war=False)
+ self.perror(err)
self.last_result = cmd2.CommandResult(out, err, data)
# Enable tab completion for cd command
@@ -98,7 +98,7 @@ class CmdLineApp(cmd2.Cmd):
"""List contents of current directory."""
# No arguments for this command
if unknown:
- self.pexcept("dir does not take any positional arguments:", traceback_war=False)
+ self.perror("dir does not take any positional arguments:")
self.do_help('dir')
self.last_result = cmd2.CommandResult('', 'Bad arguments')
return
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index dac034ef..f4c8d3e7 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -1901,14 +1901,14 @@ class ColorsApp(cmd2.Cmd):
def do_echo(self, args):
self.poutput(args)
- self.pexcept(args, traceback_war=False)
+ self.perror(args)
def do_echo_error(self, args):
color_on = Fore.RED + Back.BLACK
color_off = Style.RESET_ALL
self.poutput(color_on + args + color_off)
- # pexcept uses colors by default
- self.pexcept(args, traceback_war=False)
+ # perror uses colors by default
+ self.perror(args)
def test_colors_default():
app = ColorsApp()