Skip to content
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
4 changes: 2 additions & 2 deletions cmd2/argparse_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1250,10 +1250,10 @@ def error(self, message: str) -> NoReturn:

self.print_usage(sys.stderr)

# Add error style to message
# Use console to add style since it will respect ALLOW_STYLE's value
console = self._get_formatter().console
with console.capture() as capture:
console.print(formatted_message, style=Cmd2Style.ERROR, crop=False)
console.print(formatted_message, style=Cmd2Style.ERROR)
formatted_message = f"{capture.get()}"

self.exit(2, f'{formatted_message}\n')
Expand Down
3 changes: 0 additions & 3 deletions cmd2/rich_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,6 @@ def rich_text_to_string(text: Text) -> str:
force_terminal=True,
soft_wrap=True,
no_color=False,
markup=False,
emoji=False,
highlight=False,
theme=APP_THEME,
)
with console.capture() as capture:
Expand Down
14 changes: 12 additions & 2 deletions tests/test_cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2524,10 +2524,20 @@ def test_get_settable_choices(base_app: cmd2.Cmd) -> None:
cur_settable = base_app.settables.get(cur_choice.text)
assert cur_settable is not None

# Convert fields so we can compare them
str_value = str(cur_settable.value)

choice_value = cur_choice.table_row[0]
if isinstance(choice_value, Text):
choice_value = ru.rich_text_to_string(choice_value)

choice_description = cur_choice.table_row[1]
if isinstance(choice_description, Text):
choice_description = ru.rich_text_to_string(choice_description)

assert str_value in cur_choice.display_meta
assert ru.rich_text_to_string(cur_choice.table_row[0]) == str_value
assert ru.rich_text_to_string(cur_choice.table_row[1]) == cur_settable.description
assert choice_value == str_value
assert choice_description == cur_settable.description


def test_alias_no_subcommand(base_app) -> None:
Expand Down
Loading