diff options
| author | Eric Lin <anselor@gmail.com> | 2018-04-15 12:59:25 -0700 |
|---|---|---|
| committer | Eric Lin <anselor@gmail.com> | 2018-04-15 12:59:25 -0700 |
| commit | 874f8842fe685f63d344aa2c58c470f6c3603c3e (patch) | |
| tree | 506abfea85068d3ff86f90b25afa5a7d6b5613ea /examples | |
| parent | e20f7ec3850db2658053f73f5c9023868d7f12c7 (diff) | |
| parent | 8aaf6f431ef5e0f5e4e55759a08a22a4591d8f6b (diff) | |
| download | cmd2-git-874f8842fe685f63d344aa2c58c470f6c3603c3e.tar.gz | |
Merge remote-tracking branch 'origin/master' into autocompleter
Diffstat (limited to 'examples')
| -rwxr-xr-x | examples/argparse_example.py | 27 | ||||
| -rwxr-xr-x | examples/tab_completion.py | 4 |
2 files changed, 3 insertions, 28 deletions
diff --git a/examples/argparse_example.py b/examples/argparse_example.py index fbb2b1dc..ca2173e7 100755 --- a/examples/argparse_example.py +++ b/examples/argparse_example.py @@ -14,8 +14,7 @@ verifying that the output produced matches the transcript. import argparse import sys -from cmd2 import Cmd, options, with_argparser, with_argument_list -from optparse import make_option +from cmd2 import Cmd, with_argparser, with_argument_list class CmdLineApp(Cmd): @@ -85,30 +84,6 @@ class CmdLineApp(Cmd): self.perror("tagg requires at least 2 arguments") - # @options uses the python optparse module which has been deprecated - # since 2011. Use @with_argument_parser instead, which utilizes the - # python argparse module - @options([make_option('-p', '--piglatin', action="store_true", help="atinLay"), - make_option('-s', '--shout', action="store_true", help="N00B EMULATION MODE"), - make_option('-r', '--repeat', type="int", help="output [n] times") - ]) - def do_deprecated_speak(self, arg, opts=None): - """Repeats what you tell me to.""" - words = [] - for word in arg: - if opts.piglatin: - word = '%s%say' % (word[1:], word[0]) - if opts.shout: - arg = arg.upper() - words.append(word) - repetitions = opts.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 - - if __name__ == '__main__': # You can do your custom Argparse parsing here to meet your application's needs parser = argparse.ArgumentParser(description='Process the arguments however you like.') diff --git a/examples/tab_completion.py b/examples/tab_completion.py index 93d6c0ef..1419b294 100755 --- a/examples/tab_completion.py +++ b/examples/tab_completion.py @@ -8,8 +8,8 @@ import cmd2 from cmd2 import with_argparser, with_argument_list # List of strings used with flag and index based completion functions -food_item_strs = ['Pizza', 'Hamburger', 'Ham', 'Potato'] -sport_item_strs = ['Bat', 'Basket', 'Basketball', 'Football'] +food_item_strs = ['Pizza', 'Ham', 'Ham Sandwich', 'Potato'] +sport_item_strs = ['Bat', 'Basket', 'Basketball', 'Football', 'Space Ball'] class TabCompleteExample(cmd2.Cmd): |
