Skip to content

Commit

Permalink
Fixed issue where set command was not always printing a settable's cu…
Browse files Browse the repository at this point in the history
…rrent value.
  • Loading branch information
kmvanbrunt committed Nov 13, 2024
1 parent f159ed0 commit 88d5721
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.5.5 (TBD)
* Bug Fixes
* Fixed type hints for passing a class method to `with_argparser` and `as_subcommand_to`.
* Fixed issue where `set` command was not always printing a settable's current value.

## 2.5.4 (November 6, 2024)
* Bug Fixes
* Fixed `ZeroDivisionError` in `async_alert()` when `shutil.get_terminal_size().columns` is 0.
Expand Down
4 changes: 2 additions & 2 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4226,11 +4226,11 @@ def do_set(self, args: argparse.Namespace) -> None:
# Try to update the settable's value
try:
orig_value = settable.get_value()
new_value = settable.set_value(utils.strip_quotes(args.value))
settable.set_value(utils.strip_quotes(args.value))
except Exception as ex:
self.perror(f"Error setting {args.param}: {ex}")
else:
self.poutput(f"{args.param} - was: {orig_value!r}\nnow: {new_value!r}")
self.poutput(f"{args.param} - was: {orig_value!r}\nnow: {settable.get_value()!r}")
self.last_result = True
return

Expand Down
14 changes: 5 additions & 9 deletions cmd2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,14 @@ def get_bool_choices(_) -> List[str]: # type: ignore[no-untyped-def]
self.completer = completer

def get_value(self) -> Any:
"""
Get the value of the settable attribute
:return:
"""
"""Get the value of the settable attribute."""
return getattr(self.settable_obj, self.settable_attrib_name)

def set_value(self, value: Any) -> Any:
def set_value(self, value: Any) -> None:
"""
Set the settable attribute on the specified destination object
:param value: New value to set
:return: New value that the attribute was set to
Set the settable attribute on the specified destination object.
:param value: new value to set
"""
# Run the value through its type function to handle any conversion or validation
new_value = self.val_type(value)
Expand All @@ -205,7 +202,6 @@ def set_value(self, value: Any) -> Any:
# Check if we need to call an onchange callback
if orig_value != new_value and self.onchange_cb:
self.onchange_cb(self.name, orig_value, new_value)
return new_value


def is_text_file(file_path: str) -> bool:
Expand Down

0 comments on commit 88d5721

Please sign in to comment.