-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
cargo run --example should print available examples #2548
Comments
Sounds like a good suggestion to me! |
Can I work on this @alexcrichton? |
Certainly @SpyR1014! If you have any questions just lemme know |
I've poked around the codebase and am unsure where the best place to intercept and update this error is. Here's a commit with my attempt at handling the error. I haven't implemented the examples path logic as I feel there are other problems. The error is created by I'm not sure this is a good design, and am not familiar enough to think of another solution. Pros of the solution:
Cons:
I would appreciate any pointers before continuing. Thank you in advance for any help! :) |
Hm yeah it's true we don't have a lot of experience right now catching docopt errors and printing something as a result. I'm unfortunately not sure how we'd implement a fix for this in a "clean" fashion, so failing that I think it may be ok to special case this for now. Basically if arguments like |
Thank you so much for your response Alex. I've implemented a mostly working solution here I'm unable to figure out how to get the Because of this, the error is only updated if the cwd is the workspace root directory. This is better than nothing. Example output of running on my test file with an examples directory: Test 1
gives:
Test 2 - Empty examples directoryOutput:
Test 3 - Multiple examples
gives:
|
@AndrewJakubowicz: can you give an update on this? |
I've played with implementing this by hooking into the error, but you need the arguments to work out what examples are appropriate. Therefore, I think you need something like clap-rs/clap#1354 to implement this. |
@sanmai-NL I have not had a chance to look at this for some time or how this might work after the migration to clap. @matklad left guidance to move forward here: #5062 (comment) |
--{example,bin,bench,test} with no argument now lists all available targets ``` cargo run --bin error: "--bin" takes one argument. Available binaries: cargo error: process didn't exit successfully: `target\debug\cargo.exe run --bin` (exit code: 101) ``` Previous PR: #5062 Closes #2548 Notes: - `optional_opt` is a weird name, can someone come up with a better one? - Should I call clap's `usage()` as well when printing the error message?
if you clone a repo and has examples and you run cargo run --example you only get help for general usage, what about print the actual examples on the examples directory?
If there where one.rs, two.rs and three.rs inside examples folder it could output something like
Even more, it can autocomplete the name of the example... well that will be only a NTH.
The text was updated successfully, but these errors were encountered: