Skip to content

Commit 88d5721

Browse files
committed
Fixed issue where set command was not always printing a settable's current value.
1 parent f159ed0 commit 88d5721

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.5.5 (TBD)
2+
* Bug Fixes
3+
* Fixed type hints for passing a class method to `with_argparser` and `as_subcommand_to`.
4+
* Fixed issue where `set` command was not always printing a settable's current value.
5+
16
## 2.5.4 (November 6, 2024)
27
* Bug Fixes
38
* Fixed `ZeroDivisionError` in `async_alert()` when `shutil.get_terminal_size().columns` is 0.

cmd2/cmd2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4226,11 +4226,11 @@ def do_set(self, args: argparse.Namespace) -> None:
42264226
# Try to update the settable's value
42274227
try:
42284228
orig_value = settable.get_value()
4229-
new_value = settable.set_value(utils.strip_quotes(args.value))
4229+
settable.set_value(utils.strip_quotes(args.value))
42304230
except Exception as ex:
42314231
self.perror(f"Error setting {args.param}: {ex}")
42324232
else:
4233-
self.poutput(f"{args.param} - was: {orig_value!r}\nnow: {new_value!r}")
4233+
self.poutput(f"{args.param} - was: {orig_value!r}\nnow: {settable.get_value()!r}")
42344234
self.last_result = True
42354235
return
42364236

cmd2/utils.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,14 @@ def get_bool_choices(_) -> List[str]: # type: ignore[no-untyped-def]
178178
self.completer = completer
179179

180180
def get_value(self) -> Any:
181-
"""
182-
Get the value of the settable attribute
183-
:return:
184-
"""
181+
"""Get the value of the settable attribute."""
185182
return getattr(self.settable_obj, self.settable_attrib_name)
186183

187-
def set_value(self, value: Any) -> Any:
184+
def set_value(self, value: Any) -> None:
188185
"""
189-
Set the settable attribute on the specified destination object
190-
:param value: New value to set
191-
:return: New value that the attribute was set to
186+
Set the settable attribute on the specified destination object.
187+
188+
:param value: new value to set
192189
"""
193190
# Run the value through its type function to handle any conversion or validation
194191
new_value = self.val_type(value)
@@ -205,7 +202,6 @@ def set_value(self, value: Any) -> Any:
205202
# Check if we need to call an onchange callback
206203
if orig_value != new_value and self.onchange_cb:
207204
self.onchange_cb(self.name, orig_value, new_value)
208-
return new_value
209205

210206

211207
def is_text_file(file_path: str) -> bool:

0 commit comments

Comments
 (0)