brentyi / tyro

CLI interfaces & config objects, from types
https://brentyi.github.io/tyro
MIT License
467 stars 23 forks source link

subcommand_type_from_defaults for single case #150

Open jizongFox opened 1 month ago

jizongFox commented 1 month ago

Hello,

Thank you for this great work, supporting most of my current works.

I usually use subcommand_type_from_defaults to create subcmds with different default parameters. If worked fine even if I just specific one default parameter, such as:

config = tyro.cli(
    tyro.extras.subcommand_type_from_defaults({"_": exp_config, })
)

This is useful when just providing one default parameter, without asking for switching.

With the update of 0.8.5, it breaks. I am wondering what would be the alternative, if I don't want to re-assign the class definition.

Best, Jizong

brentyi commented 1 month ago

Hi, thanks for the issue! I'm glad you find the library useful and I'm sorry for breaking this...

If you have only one default you can do:

tyro.cli(ExpConfigClass, default=exp_config)

Do you mind checking if this does what you want? I could also remove the assert statement that I expect is complaining for you, it just felt confusing for the subcommand_type_from_defaults() function to return a type that doesn't end up creating subcommands.

jizongFox commented 1 month ago

This is exactly what I need. thank you!