You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my program, I defined my configuration options as their own dataclass, so that the config could more easily be passed around between functions that need it. I was able to integrate clize with this approach remarkably cleanly:
fromdataclassesimportdataclass@dataclass(kw_only=True)classMyConfig:
""" An example program. :param foo: foo docs :param bar: bar docs """# this docstring is used by clizefoo: int=1bar: int=2defmain(cfg: MyConfig):
print("running main with cfg:", cfg)
if__name__=="__main__":
fromclizeimportClizeimportsystry:
cli=clize.Clize.get_cli(MyConfig)
cfg=cli(*sys.argv)
iftype(cfg) isnotMyConfig:
print(cfg)
else:
main(cfg)
exceptclize.errors.ArgumentErrorase:
print(e)
However, it's a bit unergonomic. I have to import sys myself, and I lose out on the _fix_argv functionality that run() would normally do internally, and I have to implement help/error printing myself too.
For this to happen, run() would have to return ret, in the case that exit is not called explicitly, as opposed to the current behaviour that just returns None.
The text was updated successfully, but these errors were encountered:
In my program, I defined my configuration options as their own dataclass, so that the config could more easily be passed around between functions that need it. I was able to integrate clize with this approach remarkably cleanly:
However, it's a bit unergonomic. I have to
import sys
myself, and I lose out on the_fix_argv
functionality thatrun()
would normally do internally, and I have to implement help/error printing myself too.I think it would be nice if I could just do this:
For this to happen,
run()
would have to returnret
, in the case that exit is not called explicitly, as opposed to the current behaviour that just returns None.The text was updated successfully, but these errors were encountered: