eonu / feud

Build powerful CLIs with simple idiomatic Python, driven by type hints. Not all arguments are bad.
https://feud.readthedocs.io
MIT License
57 stars 2 forks source link

Seamless integration with existing click CLI #162

Open vikigenius opened 2 weeks ago

vikigenius commented 2 weeks ago

Does this suggestion already exist?

Feature description

Take for instance I am using the Litestar framework that already has an extensive CLI implemented on top of click.

I want to extend it by adding additional commands instead of rewriting the entire CLI myself (maybe in the future).

Is there an easy way I can simply do something like

existing_cli.add_command(Blog)  # Blog is a feud.Group
eonu commented 2 weeks ago

Hey @vikigenius, thanks for checking out the package.

This should be possible by using Group.compile (or feud.build) to compile the group into a Click object.

You can then add it to an existing CLI.

import feud

# your existing Litestar CLI (a click.Group object)
type(existing_cli)
# <class 'click.Group'>

# your defined feud.Group
class Blog(feud.Group):
    ...

# compile the feud.Group into a click.Group instance
blog = Blog.compile()  # or feud.build(Blog)
type(blog)
# <class 'click.Group'>

# add the compiled group as a sub-command to the existing CLI
existing_cli.add_command(blog)