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

Adding the cargo doc --examples subcommand #9808

Merged
merged 9 commits into from
Sep 1, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bin/cargo/commands/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn cli() -> App {
"open",
"Opens the docs in a browser after the operation",
))
.arg(opt("examples", "Document all examples"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't actually do anything; if someone passes the option cargo will ignore it. Consider writing some tests so you can tell whether this works or not, there are lots of examples if you search for cargo_test.

I'm not super familiar with cargo's code, but I expect the right approach would be to loop over all examples and document them (maybe in parallel?). I'd look at how --example x works currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review, which is a huge encouragement to me. It works fine for my local test.

My test file directory is:

hello
├─examples
│    ├───examples1.rs
│    └───examples2.rs
└─src
   └───main.rs

image

I think it's good extensibility in the source code.

..\cargo\src\cargo\util\command_prelude.rs
filter: CompileFilter::from_raw_arguments(
                self._is_present("lib"),
                self._values_of("bin"),
                self._is_present("bins"),
                self._values_of("test"),
                self._is_present("tests"),
                self._values_of("example"),
                self._is_present("examples"),     // examples
                self._values_of("bench"),
                self._is_present("benches"),
                self._is_present("all-targets"),
            ),

.arg_package_spec(
"Package to document",
"Document all packages in the workspace",
Expand Down