File tree Expand file tree Collapse file tree 5 files changed +19
-11
lines changed Expand file tree Collapse file tree 5 files changed +19
-11
lines changed Original file line number Diff line number Diff line change 10
10
- Moved all string-related functions from utils.py to string_utils.py.
11
11
- Removed all text style Enums from ansi.py in favor of ` Rich ` styles.
12
12
- Renamed ansi.py to terminal_utils.py to reflect the functions left in it.
13
+ - Replaced ` utils.Settable.get_value() ` and ` utils.Settable.set_value() ` in favor of a Python
14
+ property called ` Settable.value ` .
13
15
14
16
- Enhancements
15
17
- Simplified the process to set a custom parser for ` cmd2's ` built-in commands. See
Original file line number Diff line number Diff line change @@ -2509,7 +2509,7 @@ def _get_settable_completion_items(self) -> list[CompletionItem]:
2509
2509
2510
2510
for name , settable in self .settables .items ():
2511
2511
descriptive_data = [
2512
- str (settable .get_value () ),
2512
+ str (settable .value ),
2513
2513
settable .description ,
2514
2514
]
2515
2515
results .append (CompletionItem (name , descriptive_data ))
@@ -4460,12 +4460,12 @@ def do_set(self, args: argparse.Namespace) -> None:
4460
4460
if args .value :
4461
4461
# Try to update the settable's value
4462
4462
try :
4463
- orig_value = settable .get_value ()
4464
- settable .set_value ( su .strip_quotes (args .value ) )
4463
+ orig_value = settable .value
4464
+ settable .value = su .strip_quotes (args .value )
4465
4465
except ValueError as ex :
4466
4466
self .perror (f"Error setting { args .param } : { ex } " )
4467
4467
else :
4468
- self .poutput (f"{ args .param } - was: { orig_value !r} \n now: { settable .get_value () !r} " )
4468
+ self .poutput (f"{ args .param } - was: { orig_value !r} \n now: { settable .value !r} " )
4469
4469
self .last_result = True
4470
4470
return
4471
4471
@@ -4492,10 +4492,10 @@ def do_set(self, args: argparse.Namespace) -> None:
4492
4492
settable = self .settables [param ]
4493
4493
settable_table .add_row (
4494
4494
param ,
4495
- str (settable .get_value () ),
4495
+ str (settable .value ),
4496
4496
settable .description ,
4497
4497
)
4498
- self .last_result [param ] = settable .get_value ()
4498
+ self .last_result [param ] = settable .value
4499
4499
4500
4500
self .poutput ()
4501
4501
self .poutput (settable_table )
Original file line number Diff line number Diff line change @@ -40,6 +40,10 @@ def __str__(self) -> str:
40
40
"""Return value instead of enum name for printing in cmd2's set command."""
41
41
return str (self .value )
42
42
43
+ def __repr__ (self ) -> str :
44
+ """Return quoted value instead of enum description for printing in cmd2's set command."""
45
+ return repr (self .value )
46
+
43
47
44
48
# Controls when ANSI style sequences are allowed in output
45
49
ALLOW_STYLE = AllowStyle .TERMINAL
Original file line number Diff line number Diff line change @@ -126,11 +126,13 @@ def get_bool_choices(_: str) -> list[str]:
126
126
self .choices_provider = choices_provider
127
127
self .completer = completer
128
128
129
- def get_value (self ) -> Any :
129
+ @property
130
+ def value (self ) -> Any :
130
131
"""Get the value of the settable attribute."""
131
132
return getattr (self .settable_obj , self .settable_attrib_name )
132
133
133
- def set_value (self , value : Any ) -> None :
134
+ @value .setter
135
+ def value (self , value : Any ) -> None :
134
136
"""Set the settable attribute on the specified destination object.
135
137
136
138
:param value: new value to set
@@ -144,7 +146,7 @@ def set_value(self, value: Any) -> None:
144
146
raise ValueError (f"invalid choice: { new_value !r} (choose from { choices_str } )" )
145
147
146
148
# Try to update the settable's value
147
- orig_value = self .get_value ()
149
+ orig_value = self .value
148
150
setattr (self .settable_obj , self .settable_attrib_name , new_value )
149
151
150
152
# Check if we need to call an onchange callback
Original file line number Diff line number Diff line change @@ -153,7 +153,7 @@ def test_base_set(base_app) -> None:
153
153
# Make sure all settables appear in last_result.
154
154
assert len (base_app .last_result ) == len (base_app .settables )
155
155
for param in base_app .last_result :
156
- assert base_app .last_result [param ] == base_app .settables [param ].get_value ()
156
+ assert base_app .last_result [param ] == base_app .settables [param ].value
157
157
158
158
159
159
def test_set (base_app ) -> None :
@@ -2279,7 +2279,7 @@ def test_get_settable_completion_items(base_app) -> None:
2279
2279
2280
2280
# These CompletionItem descriptions are a two column table (Settable Value and Settable Description)
2281
2281
# First check if the description text starts with the value
2282
- str_value = str (cur_settable .get_value () )
2282
+ str_value = str (cur_settable .value )
2283
2283
assert cur_res .descriptive_data [0 ].startswith (str_value )
2284
2284
2285
2285
# The second column is likely to have wrapped long text. So we will just examine the
You can’t perform that action at this time.
0 commit comments