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

Adds just::run_with_args to provide arguments from Rust code #2172

Closed
wants to merge 1 commit into from

Conversation

EnigmaCurry
Copy link
Contributor

This adds a new method to run just commands passed from a Vec<&str>.

I found this blog post where I copied this pattern for optional arguments, I didn't want to mess with the original arity of the run() method, so I made a second method for passing args, and a third to consolidate the common logic, but maybe there's a better way?

This example runs the foo target:

cargo run --example run-with-args
 ## (stdout): bar

I don't quite know how to test this yet either, because I'm not forking the process, I don't think I can capture stdout like the other tests do.

@casey
Copy link
Owner

casey commented Jun 19, 2024

Thanks for the PR!

I think it's fine to just have a single run() which takes arguments, and pass in std::env::args_os() from main. Also, this is small enough that I don't think it needs to be tested. I merged #2173 which does this.

A couple things to keep in mind when using just as a library:

  • Since just is primarily a CLI tool, the library interface doesn't have any kind of semantic versioning guarantees, and may wind up breaking or changing.

  • Also, run() will not return if the command line arguments can't be parsed, since currently we call get_matches_from() which will exit on error. This could be changed without too much work, and make run() return an error instead of exiting when the args can't be parsed.

I added docs to this effect in #2174.

@casey casey closed this Jun 19, 2024
@EnigmaCurry
Copy link
Contributor Author

Thanks!

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