Skip to content

Commit 6cb882e

Browse files
committed
Changed examples to reflect that settable doesn't need to be updated before calling init()
1 parent 6e4d480 commit 6cb882e

File tree

9 files changed

+32
-18
lines changed

9 files changed

+32
-18
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,14 @@ class CmdLineApp(cmd2.Cmd):
242242
self.multiline_commands = ['orate']
243243
self.maxrepeats = 3
244244

245-
# Add stuff to settable and shortcuts before calling base class initializer
246-
self.settable['maxrepeats'] = 'max repetitions for speak command'
245+
# Add stuff to shortcuts before calling base class initializer
247246
self.shortcuts.update({'&': 'speak'})
248247

249248
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
250249
super().__init__(use_ipython=False)
250+
251+
# Make maxrepeats settable at runtime
252+
self.settable['maxrepeats'] = 'max repetitions for speak command'
251253

252254
speak_parser = argparse.ArgumentParser()
253255
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')

examples/cmd_as_argument.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ def __init__(self):
3333
self.multiline_commands = ['orate']
3434
self.maxrepeats = 3
3535

36-
# Add stuff to settable and shortcuts before calling base class initializer
37-
self.settable['maxrepeats'] = 'max repetitions for speak command'
36+
# Add stuff to shortcuts before calling base class initializer
3837
self.shortcuts.update({'&': 'speak'})
3938

4039
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
4140
super().__init__(use_ipython=False)
4241

42+
# Make maxrepeats settable at runtime
43+
self.settable['maxrepeats'] = 'max repetitions for speak command'
44+
4345
speak_parser = argparse.ArgumentParser()
4446
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
4547
speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')

examples/colors.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ def __init__(self):
6666
self.multiline_commands = ['orate']
6767
self.maxrepeats = 3
6868

69-
# Add stuff to settable and shortcuts before calling base class initializer
70-
self.settable['maxrepeats'] = 'max repetitions for speak command'
69+
# Add stuff to shortcuts before calling base class initializer
7170
self.shortcuts.update({'&': 'speak'})
7271

7372
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
7473
super().__init__(use_ipython=True)
7574

75+
# Make maxrepeats settable at runtime
76+
self.settable['maxrepeats'] = 'max repetitions for speak command'
77+
7678
speak_parser = argparse.ArgumentParser()
7779
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
7880
speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')

examples/decorator_example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ def __init__(self, ip_addr=None, port=None, transcript_files=None):
2323
self.shortcuts.update({'&': 'speak'})
2424
self.maxrepeats = 3
2525

26-
# Add stuff to settable and/or shortcuts before calling base class initializer
27-
self.settable['maxrepeats'] = 'Max number of `--repeat`s allowed'
28-
2926
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
3027
super().__init__(use_ipython=False, transcript_files=transcript_files)
3128

29+
# Make maxrepeats settable at runtime
30+
self.settable['maxrepeats'] = 'Max number of `--repeat`s allowed'
31+
3232
# Disable cmd's usage of command-line arguments as commands to be run at invocation
3333
# self.allow_cli_args = False
3434

examples/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class EnvironmentApp(cmd2.Cmd):
1414
sunny = False
1515

1616
def __init__(self):
17+
super().__init__()
1718
self.settable.update({'degrees_c': 'Temperature in Celsius'})
1819
self.settable.update({'sunny': 'Is it sunny outside?'})
19-
super().__init__()
2020

2121
def do_sunbathe(self, arg):
2222
if self.degrees_c < 20:

examples/example.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ def __init__(self):
3030
self.multiline_commands = ['orate']
3131
self.maxrepeats = 3
3232

33-
# Add stuff to settable and shortcuts before calling base class initializer
34-
self.settable['maxrepeats'] = 'max repetitions for speak command'
33+
# Add stuff to shortcuts before calling base class initializer
3534
self.shortcuts.update({'&': 'speak'})
3635

3736
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
3837
super().__init__(use_ipython=False)
3938

39+
# Make maxrepeats settable at runtime
40+
self.settable['maxrepeats'] = 'max repetitions for speak command'
41+
4042
speak_parser = argparse.ArgumentParser()
4143
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
4244
speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')

examples/pirate.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ def __init__(self):
3232
self.terminators = self.terminators + ['...']
3333
self.songcolor = Fore.BLUE
3434

35-
# Add stuff to settable and/or shortcuts before calling base class initializer
36-
self.settable['songcolor'] = 'Color to ``sing`` in (black/red/green/yellow/blue/magenta/cyan/white)'
35+
# Add stuff to shortcuts before calling base class initializer
3736
self.shortcuts.update({'~': 'sing'})
3837

3938
"""Initialize the base class as well as this one"""
4039
super().__init__()
40+
41+
# Make songcolor settable at runtime
42+
self.settable['songcolor'] = 'Color to ``sing`` in (black/red/green/yellow/blue/magenta/cyan/white)'
43+
4144
# prompts and defaults
4245
self.gold = 0
4346
self.initial_gold = self.gold

examples/plumbum_colors.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ def __init__(self):
6969
self.multiline_commands = ['orate']
7070
self.maxrepeats = 3
7171

72-
# Add stuff to settable and shortcuts before calling base class initializer
73-
self.settable['maxrepeats'] = 'max repetitions for speak command'
72+
# Add stuff to shortcuts before calling base class initializer
7473
self.shortcuts.update({'&': 'speak'})
7574

7675
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
7776
super().__init__(use_ipython=True)
7877

78+
# Make maxrepeats settable at runtime
79+
self.settable['maxrepeats'] = 'max repetitions for speak command'
80+
7981
speak_parser = argparse.ArgumentParser()
8082
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
8183
speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')

tests/test_transcript.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ def __init__(self, *args, **kwargs):
3232
self.multiline_commands = ['orate']
3333
self.maxrepeats = 3
3434

35-
# Add stuff to settable and/or shortcuts before calling base class initializer
35+
super().__init__(*args, **kwargs)
36+
37+
# Make maxrepeats settable at runtime
3638
self.settable['maxrepeats'] = 'Max number of `--repeat`s allowed'
3739

38-
super().__init__(*args, **kwargs)
3940
self.intro = 'This is an intro banner ...'
4041

4142
speak_parser = argparse.ArgumentParser()

0 commit comments

Comments
 (0)