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
I think we should create a context manager, something to be used like:
with craft_cli.app_wrapper(...) as dispatcher:
dispatcher.pre_parse_args(sys.argv[1:])
dispatcher.load_command(None)
dispatcher.run()
sys.exit(dispatcher.return_code)
instantiate Dispatcher with proper values and return it as the object to be used
"hide" the handling of specific ArgumentParsingError and ProvideHelpException; for these both cases it would automatically show messages and cut further execution, leaving dispatcher.return_code with the proper value
also hide catching CraftError, KeyboardInterrupt and generic Exception, doing the right thing in each case
provide a simpler and direct to use return code
Improvements:
Much simpler to use
Less error prone as no comple structure is needed just for the lib to work
No need to expose internal exceptions in the simple usage at least: ArgumentParsingError should remain public because it's handy for the command to expose a complicated argument parsing failure, but it doesn't need to be presented to the developer the first time she reads about this lib; ProvideHelpException could be made private (OTOH is ok to leave it public if the developer needs to fallback into a more "manual" usage of the lib because of advance needs).
The lib should provide a way to handle the application bootstrapping and finishing (in several ways: ok, error, etc).
The code is already in Charmcraft, we need to move it in here.
The text was updated successfully, but these errors were encountered: