diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-11-09 02:32:36 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-11-09 02:32:36 -0500 |
commit | 5fa0916115faf55fb513161b4de0d9d8544bcbc2 (patch) | |
tree | ce6549cc84a3d4d27c7a94fde1417fed4f550e08 /docs/settingchanges.rst | |
parent | 24af59ee70827d252150f14da9de1d263af9d86a (diff) | |
download | cmd2-git-5fa0916115faf55fb513161b4de0d9d8544bcbc2.tar.gz |
Updated docs to make it more clear that you need to update shortcuts attribute before calling super class __init__
Diffstat (limited to 'docs/settingchanges.rst')
-rw-r--r-- | docs/settingchanges.rst | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/docs/settingchanges.rst b/docs/settingchanges.rst index 326db3f5..0a24651b 100644 --- a/docs/settingchanges.rst +++ b/docs/settingchanges.rst @@ -19,11 +19,11 @@ Whether or not you set ``case_insensitive``, *please do not* define command method names with any uppercase letters. ``cmd2`` expects all command methods to be lowercase. -Shortcuts -========= +Shortcuts (command aliases) +=========================== -Special-character shortcuts for common commands can make life more convenient for your -users. Shortcuts are used without a space separating them from their arguments, +Command aliases for long command names such as special-character shortcuts for common commands can make life more +convenient for your users. Shortcuts are used without a space separating them from their arguments, like ``!ls``. By default, the following shortcuts are defined: ``?`` @@ -42,7 +42,20 @@ To define more shortcuts, update the dict ``App.shortcuts`` with the {'shortcut': 'command_name'} (omit ``do_``):: class App(Cmd2): - Cmd2.shortcuts.update({'*': 'sneeze', '~': 'squirm'}) + def __init__(self): + # Make sure you update the shortcuts attribute before calling the super class __init__ + self.shortcuts.update({'*': 'sneeze', '~': 'squirm'}) + + # Make sure to call this super class __init__ after updating shortcuts + cmd2.Cmd.__init__(self) + +.. warning:: + + Command aliases needed to be created by updating the ``shortcuts`` dictionary attribute prior to calling the + ``cmd2.Cmd`` super class ``__init__()`` method. Moreover, that super class init method needs to be called after + updating the ``shortcuts`` attribute This warning applies in general to many other attributes which are not + settable at runtime such as ``commentGrammars``, ``multilineCommands``, etc. + Default to shell ================ |