I would like to integrate a python CLI written using click into a python CLI application built using another framework. Rewriting the calling application is not an option.
As part of the integration, I need to invoke the click CLI from within code passing the arguments it should consume directly. How do I do this?
For a concrete example, consider that I'd invoke this as foobar theclickcli <args> where foobar is the CLI not written in click and theclickcli is a subcommand that should invoke my click CLI with its arguments (<args>).
I see that click offers the click.testing.CLIRunner class which allows invoking a group or command. However, the documentation notes that:
"...[this] should really only be used for testing as they change the entire interpreter state for simplicity and are not in any way thread-safe".
Is there an "idiomatic" way of invoking a click CLI (not just a subcommand) given an argv argument list like in argparse?
from Launch Click CLI Application from inside python code
No comments:
Post a Comment