diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-11-09 02:46:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-09 02:46:11 -0500 |
commit | af06c06a5e580c92cf934f110c9e88ec75cde235 (patch) | |
tree | ce6549cc84a3d4d27c7a94fde1417fed4f550e08 /examples | |
parent | 24af59ee70827d252150f14da9de1d263af9d86a (diff) | |
parent | 5fa0916115faf55fb513161b4de0d9d8544bcbc2 (diff) | |
download | cmd2-git-af06c06a5e580c92cf934f110c9e88ec75cde235.tar.gz |
Merge pull request #235 from python-cmd2/command_aliases
Updated docs to make updating shortcuts more clear
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/arg_print.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/examples/arg_print.py b/examples/arg_print.py index 20fa7c02..849cf386 100755 --- a/examples/arg_print.py +++ b/examples/arg_print.py @@ -6,6 +6,8 @@ This is intended to serve as a live demonstration so that developers can experiment with and understand how command and argument parsing is intended to work. + +It also serves as an example of how to create command aliases (shortcuts). """ import pyparsing import cmd2 @@ -19,8 +21,13 @@ class ArgumentAndOptionPrinter(cmd2.Cmd): # Uncomment this line to disable Python-style comments but still allow C-style comments # self.commentGrammars = pyparsing.Or([pyparsing.cStyleComment]) - # Make sure to call this super class __init__ after setting commentGrammars and not before + # Create command aliases which are shorter + self.shortcuts.update({'ap': 'aprint', 'op': 'oprint'}) + + # Make sure to call this super class __init__ *after* setting commentGrammars and/or updating shortcuts cmd2.Cmd.__init__(self) + # NOTE: It is critical that the super class __init__ method be called AFTER updating certain parameters which + # are not settable at runtime. This includes the commentGrammars, shortcuts, multilineCommands, etc. def do_aprint(self, arg): """Print the argument string this basic command is called with.""" |