summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorxNinjaKittyx <sangbumahn@gmail.com>2019-06-24 17:54:15 -0700
committerxNinjaKittyx <sangbumahn@gmail.com>2019-06-24 17:54:15 -0700
commite8206628eefe8234cb5118807c6f40e983c2a316 (patch)
tree455fda269bf89e5a6195059083179b8b44d51754 /examples
parentbef07746e33da9def33d814913891384a545a95c (diff)
downloadcmd2-git-e8206628eefe8234cb5118807c6f40e983c2a316.tar.gz
Initial Commit for Issue 698
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/paged_output.py6
-rwxr-xr-xexamples/pirate.py7
-rwxr-xr-xexamples/python_scripting.py6
3 files changed, 9 insertions, 10 deletions
diff --git a/examples/paged_output.py b/examples/paged_output.py
index b3824012..4986168b 100755
--- a/examples/paged_output.py
+++ b/examples/paged_output.py
@@ -22,7 +22,7 @@ class PagedOutput(cmd2.Cmd):
text = f.read()
self.ppaged(text, chop=chop)
except FileNotFoundError:
- self.perror('ERROR: file {!r} not found'.format(filename), traceback_war=False)
+ self.pexcept('ERROR: file {!r} not found'.format(filename), traceback_war=False)
@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.perror('page_wrap requires a path to a file as an argument', traceback_war=False)
+ self.pexcept('page_wrap requires a path to a file as an argument', traceback_war=False)
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.perror('page_truncate requires a path to a file as an argument', traceback_war=False)
+ self.pexcept('page_truncate requires a path to a file as an argument', traceback_war=False)
return
self.page_file(args[0], chop=True)
diff --git a/examples/pirate.py b/examples/pirate.py
index 699ee80c..57ac0b53 100755
--- a/examples/pirate.py
+++ b/examples/pirate.py
@@ -34,7 +34,7 @@ class Pirate(cmd2.Cmd):
super().__init__(multiline_commands=['sing'], terminators=[MULTILINE_TERMINATOR, '...'], shortcuts=shortcuts)
self.default_to_shell = True
- self.songcolor = Fore.BLUE
+ self.songcolor = 'blue'
# Make songcolor settable at runtime
self.settable['songcolor'] = 'Color to ``sing`` in (black/red/green/yellow/blue/magenta/cyan/white)'
@@ -82,8 +82,7 @@ class Pirate(cmd2.Cmd):
def do_sing(self, arg):
"""Sing a colorful song."""
- color_escape = COLORS.get(self.songcolor, Fore.RESET)
- self.poutput(arg, color=color_escape)
+ self.poutput(arg, fg=self.songcolor)
yo_parser = argparse.ArgumentParser()
yo_parser.add_argument('--ho', type=int, default=2, help="How often to chant 'ho'")
@@ -101,7 +100,7 @@ class Pirate(cmd2.Cmd):
if __name__ == '__main__':
import sys
- # Create an instance of the Pirate derived class and enter the REPL with cmdlooop().
+ # Create an instance of the Pirate derived class and enter the REPL with cmdloop().
pirate = Pirate()
sys_exit_code = pirate.cmdloop()
print('Exiting with code: {!r}'.format(sys_exit_code))
diff --git a/examples/python_scripting.py b/examples/python_scripting.py
index c45648bc..f9461fa5 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.perror("cd requires exactly 1 argument:", traceback_war=False)
+ self.pexcept("cd requires exactly 1 argument:", traceback_war=False)
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.perror(err, traceback_war=False)
+ self.pexcept(err, traceback_war=False)
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.perror("dir does not take any positional arguments:", traceback_war=False)
+ self.pexcept("dir does not take any positional arguments:", traceback_war=False)
self.do_help('dir')
self.last_result = cmd2.CommandResult('', 'Bad arguments')
return