Skip to content

Fixed issue where set command was not always printing a settable's current value. #1380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading