Textualize / trogon

Easily turn your Click CLI into a powerful terminal application
MIT License
2.4k stars 54 forks source link

Nicer handling of callable defaults #51

Open chrisjsewell opened 1 year ago

chrisjsewell commented 1 year ago

Currently, if you have an option that sets a callable default, it will simply show the str format of it, e.g. if you have:

def my_default():
    return "hi"

@click.command()
@click.option('-o', default=my_default)
def command(option): ...

it will show as <function my_default at 0x10f0fb040>

Obviously, it would be nice if there was a better representation thanks (or just no default was shown)

boehmseb commented 6 months ago

This becomes a bigger issue if used with a click.Choice because the string representation of the function object is obviously not contained in the allowed values: InvalidSelectValueError: Illegal select value '<function <lambda> at 0x7f426eb0b100>'