Skip to content

Commit 8cf0b30

Browse files
committed
Updated docs to reflect that shortcuts are now passed into the super class initializer
1 parent cfcff77 commit 8cf0b30

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,11 @@ class CmdLineApp(cmd2.Cmd):
240240

241241
def __init__(self):
242242
self.maxrepeats = 3
243-
244-
# Add stuff to shortcuts before calling base class initializer
245-
self.shortcuts.update({'&': 'speak'})
243+
shortcuts = dict(self.DEFAULT_SHORTCUTS)
244+
shortcuts.update({'&': 'speak'})
246245

247246
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
248-
super().__init__(use_ipython=False, multiline_commands=['orate'])
247+
super().__init__(use_ipython=False, multiline_commands=['orate'], shortcuts=shortcuts)
249248

250249
# Make maxrepeats settable at runtime
251250
self.settable['maxrepeats'] = 'max repetitions for speak command'

docs/settingchanges.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ To define more shortcuts, update the dict ``App.shortcuts`` with the
3333

3434
class App(Cmd2):
3535
def __init__(self):
36-
# Make sure you update the shortcuts attribute before calling the super class __init__
37-
self.shortcuts.update({'*': 'sneeze', '~': 'squirm'})
38-
39-
# Make sure to call this super class __init__ after updating shortcuts
40-
cmd2.Cmd.__init__(self)
36+
shortcuts = dict(self.DEFAULT_SHORTCUTS)
37+
shortcuts.update({'*': 'sneeze', '~': 'squirm'})
38+
cmd2.Cmd.__init__(self, shortcuts=shortcuts)
4139

4240
.. warning::
4341

0 commit comments

Comments
 (0)