trogon icon indicating copy to clipboard operation
trogon copied to clipboard

Trogon not handling bool options

Open bigbirdcode opened this issue 9 months ago • 2 comments

I have the following example script:

import click
from trogon import tui


@tui()
@click.command()
@click.option("--my-bool", type=bool)
def cli(my_bool):
    print("Hello from trogon-try!")
    print("my-bool:", my_bool)


if __name__ == "__main__":
    cli()

When I execute it with Trogon then I get the error:

[...]

  File "c:\Users\Peter\Documents\work\trogon_try\.venv\Lib\site-packages\trogon\trogon.py", line 256, in <genexpr>
    f"Running [b cyan]{self.app_name} {' '.join(shlex.quote(s) for s in self.post_run_command)}[/]"
                                                ^^^^^^^^^^^^^^
  File "c:\python312\Lib\shlex.py", line 327, in quote
    if _find_unsafe(s) is None:
       ^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'bool'

As I have checked the details, the attribute post_run_command contains the value as bool and not str.

bigbirdcode avatar Jan 26 '25 19:01 bigbirdcode

Note: I'm using Windows, if it is OS dependent in any way.

bigbirdcode avatar Jan 26 '25 19:01 bigbirdcode

Thanks for reporting @bigbirdcode — FWIW I think Click prefers is_flag=True for this kind of option. I would probably expect type=bool to produce the same outcomes, though.

daneah avatar Mar 06 '25 11:03 daneah