diff options
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/cmd_as_argument.py | 2 | ||||
-rwxr-xr-x | examples/colors.py | 2 | ||||
-rwxr-xr-x | examples/decorator_example.py | 2 | ||||
-rwxr-xr-x | examples/environment.py | 16 | ||||
-rwxr-xr-x | examples/example.py | 2 | ||||
-rwxr-xr-x | examples/first_app.py | 2 | ||||
-rwxr-xr-x | examples/initialization.py | 4 | ||||
-rwxr-xr-x | examples/pirate.py | 2 | ||||
-rwxr-xr-x | examples/plumbum_colors.py | 2 | ||||
-rwxr-xr-x | examples/remove_settable.py | 19 | ||||
-rwxr-xr-x | examples/table_display.py | 2 | ||||
-rw-r--r-- | examples/transcripts/exampleSession.txt | 2 | ||||
-rw-r--r-- | examples/transcripts/transcript_regex.txt | 2 |
13 files changed, 42 insertions, 17 deletions
diff --git a/examples/cmd_as_argument.py b/examples/cmd_as_argument.py index 08643a50..b65bcbcb 100755 --- a/examples/cmd_as_argument.py +++ b/examples/cmd_as_argument.py @@ -36,7 +36,7 @@ class CmdLineApp(cmd2.Cmd): self.self_in_py = True self.maxrepeats = 3 # Make maxrepeats settable at runtime - self.settable['maxrepeats'] = 'max repetitions for speak command' + self.add_settable(cmd2.Settable('maxrepeats', int, 'max repetitions for speak command')) speak_parser = argparse.ArgumentParser() speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay') diff --git a/examples/colors.py b/examples/colors.py index bbb3b2ad..33b17e53 100755 --- a/examples/colors.py +++ b/examples/colors.py @@ -39,7 +39,7 @@ class CmdLineApp(cmd2.Cmd): self.maxrepeats = 3 # Make maxrepeats settable at runtime - self.settable['maxrepeats'] = 'max repetitions for speak command' + self.add_settable(cmd2.Settable('maxrepeats', int, 'max repetitions for speak command')) # Should ANSI color output be allowed self.allow_style = ansi.STYLE_TERMINAL diff --git a/examples/decorator_example.py b/examples/decorator_example.py index 4f68653e..0f5374ce 100755 --- a/examples/decorator_example.py +++ b/examples/decorator_example.py @@ -27,7 +27,7 @@ class CmdLineApp(cmd2.Cmd): self.maxrepeats = 3 # Make maxrepeats settable at runtime - self.settable['maxrepeats'] = 'Max number of `--repeat`s allowed' + self.add_settable(cmd2.Settable('maxrepeats', int, 'max repetitions for speak command')) # Example of args set from the command-line (but they aren't being used here) self._ip = ip_addr diff --git a/examples/environment.py b/examples/environment.py index 9e611f08..670b63ac 100755 --- a/examples/environment.py +++ b/examples/environment.py @@ -9,15 +9,19 @@ import cmd2 class EnvironmentApp(cmd2.Cmd): """ Example cmd2 application. """ - degrees_c = 22 - sunny = False - def __init__(self): super().__init__() - self.settable.update({'degrees_c': 'Temperature in Celsius'}) - self.settable.update({'sunny': 'Is it sunny outside?'}) + self.degrees_c = 22 + self.sunny = False + self.add_settable(cmd2.Settable('degrees_c', + int, + 'Temperature in Celsius', + onchange_cb=self._onchange_degrees_c + )) + self.add_settable(cmd2.Settable('sunny', bool, 'Is it sunny outside?')) def do_sunbathe(self, arg): + """Attempt to sunbathe.""" if self.degrees_c < 20: result = "It's {} C - are you a penguin?".format(self.degrees_c) elif not self.sunny: @@ -26,7 +30,7 @@ class EnvironmentApp(cmd2.Cmd): result = 'UV is bad for your skin.' self.poutput(result) - def _onchange_degrees_c(self, old, new): + def _onchange_degrees_c(self, param_name, old, new): # if it's over 40C, it's gotta be sunny, right? if new > 40: self.sunny = True diff --git a/examples/example.py b/examples/example.py index b8f8202c..0272a6e5 100755 --- a/examples/example.py +++ b/examples/example.py @@ -32,7 +32,7 @@ class CmdLineApp(cmd2.Cmd): # Make maxrepeats settable at runtime self.maxrepeats = 3 - self.settable['maxrepeats'] = 'max repetitions for speak command' + self.add_settable(cmd2.Settable('maxrepeats', int, 'max repetitions for speak command')) speak_parser = argparse.ArgumentParser() speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay') diff --git a/examples/first_app.py b/examples/first_app.py index b5bd07e9..d8272e86 100755 --- a/examples/first_app.py +++ b/examples/first_app.py @@ -27,7 +27,7 @@ class FirstApp(cmd2.Cmd): # Make maxrepeats settable at runtime self.maxrepeats = 3 - self.settable['maxrepeats'] = 'max repetitions for speak command' + self.add_settable(cmd2.Settable('maxrepeats', int, 'max repetitions for speak command')) speak_parser = argparse.ArgumentParser() speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay') diff --git a/examples/initialization.py b/examples/initialization.py index 32aa852f..c13ed137 100755 --- a/examples/initialization.py +++ b/examples/initialization.py @@ -14,6 +14,7 @@ """ import cmd2 from cmd2 import style +from cmd2.ansi import FG_COLORS class BasicApp(cmd2.Cmd): @@ -42,7 +43,8 @@ class BasicApp(cmd2.Cmd): self.foreground_color = 'cyan' # Make echo_fg settable at runtime - self.settable['foreground_color'] = 'Foreground color to use with echo command' + self.add_settable(cmd2.Settable('foreground_color', str, 'Foreground color to use with echo command', + choices=FG_COLORS)) @cmd2.with_category(CUSTOM_CATEGORY) def do_intro(self, _): diff --git a/examples/pirate.py b/examples/pirate.py index eda3994e..acbab17c 100755 --- a/examples/pirate.py +++ b/examples/pirate.py @@ -25,7 +25,7 @@ class Pirate(cmd2.Cmd): self.songcolor = 'blue' # Make songcolor settable at runtime - self.settable['songcolor'] = 'Color to ``sing`` in (black/red/green/yellow/blue/magenta/cyan/white)' + self.add_settable(cmd2.Settable('songcolor', str, 'Color to ``sing``', choices=cmd2.ansi.FG_COLORS)) # prompts and defaults self.gold = 0 diff --git a/examples/plumbum_colors.py b/examples/plumbum_colors.py index fe692805..94815f50 100755 --- a/examples/plumbum_colors.py +++ b/examples/plumbum_colors.py @@ -75,7 +75,7 @@ class CmdLineApp(cmd2.Cmd): self.maxrepeats = 3 # Make maxrepeats settable at runtime - self.settable['maxrepeats'] = 'max repetitions for speak command' + self.add_settable(cmd2.Settable('maxrepeats', int, 'max repetitions for speak command')) # Should ANSI color output be allowed self.allow_style = ansi.STYLE_TERMINAL diff --git a/examples/remove_settable.py b/examples/remove_settable.py new file mode 100755 index 00000000..6a2e4062 --- /dev/null +++ b/examples/remove_settable.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +# coding=utf-8 +""" +A sample application for cmd2 demonstrating how to remove one of the built-in runtime settable parameters. +""" +import cmd2 + + +class MyApp(cmd2.Cmd): + + def __init__(self): + super().__init__() + self.remove_settable('debug') + + +if __name__ == '__main__': + import sys + c = MyApp() + sys.exit(c.cmdloop()) diff --git a/examples/table_display.py b/examples/table_display.py index a8fd2cb0..01143598 100755 --- a/examples/table_display.py +++ b/examples/table_display.py @@ -77,7 +77,7 @@ COLUMNS = [tf.Column('City', width=11, header_halign=tf.ColumnAlignment.AlignCen # ######## Table data formatted as an iterable of python objects ######### -class CityInfo(object): +class CityInfo: """City information container""" def __init__(self, city: str, province: str, country: str, continent: str, population: int, area: float): self.city = city diff --git a/examples/transcripts/exampleSession.txt b/examples/transcripts/exampleSession.txt index 54419f91..8a60f487 100644 --- a/examples/transcripts/exampleSession.txt +++ b/examples/transcripts/exampleSession.txt @@ -3,7 +3,7 @@ # The regex for editor will match whatever program you use. # regexes on prompts just make the trailing space obvious (Cmd) set -allow_style: /(Terminal|Always|Never)/ +allow_style: '/(Terminal|Always|Never)/' debug: False echo: False editor: /.*?/ diff --git a/examples/transcripts/transcript_regex.txt b/examples/transcripts/transcript_regex.txt index 35fc5817..ce2a2beb 100644 --- a/examples/transcripts/transcript_regex.txt +++ b/examples/transcripts/transcript_regex.txt @@ -3,7 +3,7 @@ # The regex for editor will match whatever program you use. # regexes on prompts just make the trailing space obvious (Cmd) set -allow_style: /(Terminal|Always|Never)/ +allow_style: '/(Terminal|Always|Never)/' debug: False echo: False editor: /.*?/ |