Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(cli): dioxus-cli as lib #3362

Closed

Conversation

notdanilo
Copy link

Problem

While it is possible to wrap dx using std::process::Command, a more flexible and programmable approach would be to reuse dioxus-cli as a library. Publishing dioxus-cli as a library would greatly enhance its usability.

Solution

This PR exposes dioxus-cli as a library, making it possible to reuse dx instead of redirecting cli commands to it.

A good example is how bolt-cli uses anchor-cli as a library.
https://github.com/magicblock-labs/bolt/blob/main/crates/bolt-cli/src/lib.rs

@notdanilo
Copy link
Author

Thanks for running the checks. I will fix them asap.

@jkelleyrtp
Copy link
Member

Thanks! Also - do you mind adding a no_exhaustive on any structs in the public API of the cli?

I'm okay with opening up the CLI as a library but that means the CLI needs to follow semver. We should try to keep our public API minimal in that case. This means marking things as no_exhaustive where possible and not making too many things public.

@jkelleyrtp
Copy link
Member

Going to close this since it's been open for a while...

Also, having a little while to think about it, I'm not 100% sure we want to open up the CLI as a semver API. I'd be happy to accept a PR that exposes more of our types for Process/Command consumption, but I generally don't think people would even want to develop against the CLI. It's very heavy to develop against and does many weird things like overriding loggers, ctrl-c, sigkill, etc.

If you want to use the CLI from a script then I'd recommend using the types crates we provide to parse the output with JSON mode enabled.

@jkelleyrtp jkelleyrtp closed this Feb 27, 2025
@notdanilo
Copy link
Author

I had to put the web-component effort on hold. But I might come back to this as this is something that would make it easier for me to release a cli that depends on dioxus-cli

@jkelleyrtp
Copy link
Member

For sure - we could expose our CLI's arguments as an independent library instead of the entire CLI. We do that with the return types in the dioxus-dx-wire-format crate. I could see a dx-driver crate that wraps the dioxus-dx-wire-format and some Process work to allow scripting of DX

@notdanilo
Copy link
Author

But doesn't that mean that I need to ask for my cli user to download and install dioxus-cli?

@jkelleyrtp
Copy link
Member

You could download it for them with cargo-binstall. The CLI sets up lots of hooks that is going to cause trouble for the host program - the logging system, setting sigkill hooks, setting a panic handler, etc

Tools like https://github.com/dustinblackman/cargo-run-bin can automate downloading the right dx version for you, allowing you to get a handle to the program and execute it.

@notdanilo
Copy link
Author

@jkelleyrtp thanks a lot for the suggestions. I didn't know these crates :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants