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

Move CLI to rune package so it can be re-used in other projects #485

Merged
merged 3 commits into from
Apr 7, 2023

Conversation

udoprog
Copy link
Collaborator

@udoprog udoprog commented Apr 7, 2023

This allows downstream projects to build a CLI which has their own context configured.

This is accomplished by adding the cli feature to rune:

rune = { version = "0.12.3", path = "../rune", features = ["cli"] }

And setup a binary with the following:

// src/bin/my_cli.rs

fn main() {
    rune::cli::Entry::new()
        .about(format_args!("My Project"))
        .context(&mut |opts| {
            let mut c = rune::Context::with_config(opts.capture.is_none())?;
            c.install(my_project::module())?;
            Ok(c)
        })
        .run();
}

It's important to obey the opts.capture option, since it will be used when running tests.

Once this is complete, you can run your binary to say build documentation or run tests:

cargo run --bin my-cli -- doc
cargo run --bin my-cli -- test

@udoprog udoprog added the enhancement New feature or request label Apr 7, 2023
@udoprog udoprog force-pushed the cli-move branch 3 times, most recently from 4c8cc1b to dcf8c97 Compare April 7, 2023 08:11
@udoprog udoprog merged commit 75da244 into main Apr 7, 2023
@udoprog udoprog deleted the cli-move branch April 7, 2023 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant