diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-01-20 20:01:24 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-01-20 20:01:24 -0500 |
commit | 6bc3c7528b02f0160c31eb008f1218ee4c3344bc (patch) | |
tree | 48f369edfa4225e38afc5eca5695c14646e54979 /examples/pirate.py | |
parent | bd948d727e0e13fa5fd77199c06fcd3dfdda9b39 (diff) | |
download | cmd2-git-6bc3c7528b02f0160c31eb008f1218ee4c3344bc.tar.gz |
History enhancements
History changes:
- Unknown commands are no longer saved in the history
- history command now has a -t option to generate a transcript based on commands in the history
Also:
- Moved examples transcripts from examples to examples/transcripts
- Added a new transcript for use with the pirate.py example
Diffstat (limited to 'examples/pirate.py')
-rwxr-xr-x | examples/pirate.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/examples/pirate.py b/examples/pirate.py index dd9fd98c..06fdb61b 100755 --- a/examples/pirate.py +++ b/examples/pirate.py @@ -25,13 +25,13 @@ class Pirate(Cmd): """Initialize the base class as well as this one""" Cmd.__init__(self) # prompts and defaults - self.gold = 3 + self.gold = 0 self.initial_gold = self.gold self.prompt = 'arrr> ' def default(self, line): """This handles unknown commands.""" - print('What mean ye by "{0}"?'.format(line)) + self.poutput('What mean ye by "{0}"?'.format(line)) def precmd(self, line): """Runs just before a command line is parsed, but after the prompt is presented.""" @@ -41,10 +41,10 @@ class Pirate(Cmd): def postcmd(self, stop, line): """Runs right before a command is about to return.""" if self.gold != self.initial_gold: - print('Now we gots {0} doubloons' + self.poutput('Now we gots {0} doubloons' .format(self.gold)) if self.gold < 0: - print("Off to debtorrr's prison.") + self.poutput("Off to debtorrr's prison.") stop = True return stop @@ -61,17 +61,17 @@ class Pirate(Cmd): self.gold -= int(arg) except ValueError: if arg: - print('''What's "{0}"? I'll take rrrum.'''.format(arg)) + self.poutput('''What's "{0}"? I'll take rrrum.'''.format(arg)) self.gold -= 1 def do_quit(self, arg): """Quit the application gracefully.""" - print("Quiterrr!") + self.poutput("Quiterrr!") return True def do_sing(self, arg): """Sing a colorful song.""" - print(self.colorize(arg, self.songcolor)) + self.poutput(self.colorize(arg, self.songcolor)) yo_parser = argparse.ArgumentParser() yo_parser.add_argument('--ho', type=int, default=2, help="How often to chant 'ho'") @@ -84,7 +84,7 @@ class Pirate(Cmd): chant = ['yo'] + ['ho'] * args.ho separator = ', ' if args.commas else ' ' chant = separator.join(chant) - print('{0} and a bottle of {1}'.format(chant, args.beverage)) + self.poutput('{0} and a bottle of {1}'.format(chant, args.beverage)) if __name__ == '__main__': |