diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-01-11 09:43:13 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-11 09:43:13 -0500 |
commit | 6895dea2e19210093e38fa411ef28dfb7f99c32c (patch) | |
tree | 23f40707099324197b47ba5a4f45dd558b6d5b82 /examples/argparse_example.py | |
parent | 0a03ab88f8bb70cc2f384c0b98a18bdead7bd417 (diff) | |
parent | 3607a39471eac8123e69b9416e6d77ce5d5b5ddf (diff) | |
download | cmd2-git-6895dea2e19210093e38fa411ef28dfb7f99c32c.tar.gz |
Merge pull request #248 from python-cmd2/argparse_bugfixes
Argparse bugfix
Diffstat (limited to 'examples/argparse_example.py')
-rwxr-xr-x | examples/argparse_example.py | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/examples/argparse_example.py b/examples/argparse_example.py index 4c5d6f59..d784ccf5 100755 --- a/examples/argparse_example.py +++ b/examples/argparse_example.py @@ -41,13 +41,13 @@ class CmdLineApp(Cmd): # self.default_to_shell = True - argparser = argparse.ArgumentParser(prog='speak') + argparser = argparse.ArgumentParser() argparser.add_argument('-p', '--piglatin', action='store_true', help='atinLay') argparser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE') argparser.add_argument('-r', '--repeat', type=int, help='output [n] times') argparser.add_argument('words', nargs='+', help='words to say') @with_argument_parser(argparser) - def do_speak(self, argv, args=None): + def do_speak(self, cmdline, args=None): """Repeats what you tell me to.""" words = [] for word in args.words: @@ -58,10 +58,7 @@ class CmdLineApp(Cmd): words.append(word) repetitions = args.repeat or 1 for i in range(min(repetitions, self.maxrepeats)): - self.stdout.write(' '.join(words)) - self.stdout.write('\n') - # self.stdout.write is better than "print", because Cmd can be - # initialized with a non-standard output destination + self.poutput(' '.join(words)) do_say = do_speak # now "say" is a synonym for "speak" do_orate = do_speak # another synonym, but this one takes multi-line input |