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

Conversation

heisen-li
Copy link
Contributor

Adding the cargo doc --examples subcommand

#4508

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 19, 2021
@@ -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"),
            ),

@ehuss
Copy link
Contributor

ehuss commented Aug 23, 2021

Thanks for the PR!

Just a few questions/comments:

  • Can you say more about the use case here? Do you have a public project that demonstrates where this would be useful? It seems a bit unusual since you can't use example libraries as a dependency.
  • I would probably just update arg_targets_lib_bin to add examples instead of adding a separate argument here, since cargo doc is the only command that uses arg_targets_lib_bin.
  • This should probably support both --examples and --example.
  • All additions need tests to be added. There's more information at https://doc.crates.io/contrib/tests/index.html about writing and running tests.
  • CLI changes need to be added to the man pages. There is some documentation here that explains how that works.

@heisen-li
Copy link
Contributor Author

Frankly, I don't have any more use cases here.I think it is a legacy issue.Maybe you're busy, so I'll help you out.

In addition, the test items I conducted locally were normal, but I failed here. Why?

@jyn514
Copy link
Member

jyn514 commented Aug 24, 2021

Can you say more about the use case here? Do you have a public project that demonstrates where this would be useful? It seems a bit unusual since you can't use example libraries as a dependency.

For consistency with the other cargo subcommands. It seems weird you can use cargo check --examples and cargo doc --example x but not cargo doc --examples.

(That said, I agree I'm not sure how useful documenting examples is, I think rust-lang/rfcs#3123 is more useful.)

@ehuss
Copy link
Contributor

ehuss commented Aug 24, 2021

In addition, the test items I conducted locally were normal, but I failed here. Why?

When changing the man pages, the build-man.sh script needs to be run to rebuild them, and then you need to check in all those changes.

@heisen-li
Copy link
Contributor Author

In addition, the test items I conducted locally were normal, but I failed here. Why?

When changing the man pages, the build-man.sh script needs to be run to rebuild them, and then you need to check in all those changes.

thanks for your advice. It's normal now.

@ehuss
Copy link
Contributor

ehuss commented Sep 1, 2021

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 1, 2021

📌 Commit 92c35f2 has been approved by ehuss

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 1, 2021
@bors
Copy link
Collaborator

bors commented Sep 1, 2021

⌛ Testing commit 92c35f2 with merge 54c341d...

@bors
Copy link
Collaborator

bors commented Sep 1, 2021

☀️ Test successful - checks-actions
Approved by: ehuss
Pushing 54c341d to master...

@bors bors merged commit 54c341d into rust-lang:master Sep 1, 2021
@heisen-li heisen-li deleted the examples branch September 1, 2021 06:12
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 1, 2021
Update cargo, books

## nomicon

2 commits in 0c7e5bd1428e7838252bb57b7f0fbfda4ec82f02..fe6227eb3c8533200c52dffa42ef1b6f2f02c40e
2021-08-04 10:18:22 -0700 to 2021-08-31 05:42:38 +0900
- update lifetime-elision to show what elided code under `rust_2018_idi… (rust-lang/nomicon#306)
- Change code for `into_iter` on the `RawVec` section for consistency/soundness (rust-lang/nomicon#302)

## cargo

8 commits in f559c109cc79fe413a8535fb620a5a58b3823d94..18751dd3f238d94d384a7fe967abfac06cbfe0b9
2021-08-26 22:54:55 +0000 to 2021-09-01 14:26:00 +0000
- print the full destination path when no track duplicates (rust-lang/cargo#9850)
- Stabilize 2021 edition (rust-lang/cargo#9800)
- Stabilize patch-in-config (and prefer config over manifest) (rust-lang/cargo#9839)
- Adding the cargo doc --examples subcommand (rust-lang/cargo#9808)
- Make library created with `cargo new` clippy happy (rust-lang/cargo#9796)
- Swap out some outdated repo urls in documentation (rust-lang/cargo#9862)
- Change `cargo fix --edition` to only fix edition lints. (rust-lang/cargo#9846)
- Show desc of well known subcommands (fmt, clippy) in cargo --list (rust-lang/cargo#9848)

## reference

1 commits in da6ea9b03f74cae0a292f40315723d7a3a973637..0e5ed7a4bec065f0cc18c35d1c904639e095314d
2021-08-19 21:28:10 -0700 to 2021-08-29 17:33:21 +0900
- expressions.md: Attempt fixing broken grammar in Mutability paragraph (rust-lang/reference#1084)

## book

1 commits in 687e21bde2ea10c261f79fa14797c5137425098d..fcb5e0ea68112d85a1d29a7a7335978ef2a02181
2021-08-18 20:48:38 -0400 to 2021-08-31 21:26:19 -0400
- Improve the reading of the code (rust-lang/book#2845)

## rustc-dev-guide

7 commits in cf0e151b7925a40f13fbc6573c6f97d5f94c7c17..95f1acf9a39d6f402f654e917e2c1dfdb779c5fc
2021-08-22 11:47:02 -0300 to 2021-08-31 12:38:30 -0500
- Add link to `Span`
- Add rustc-source to suggested rust-analyzer config (rust-lang/rustc-dev-guide#1189)
- Fix typo, clarify backtick wording, and use inline code
- Trailing date comments in a line inside of a paragraph caused beginning of a new paragraph. (rust-lang/rustc-dev-guide#1196)
- Fix warning "Renderer command uses a path relative to the renderer output directory ..." (rust-lang/rustc-dev-guide#1194)
- Fix a code block containing ```rust
- date-check: Recognize capitalized 'Date' as well

## edition-guide

1 commits in 3710b0cae783d0bcd2b42452a63b081473f5970a..2d9b1b9da706de24650fdc5c3b0182f55c82115d
2021-07-26 11:34:46 -0700 to 2021-08-31 10:44:09 +0200
- Update for 2021 stabilization (rust-lang/edition-guide#266)

## embedded-book

1 commits in 4f9fcaa30d11ba52b641e6fd5206536d65838af9..c3a51e23859554369e6bbb5128dcef0e4f159fb5
2021-08-06 17:43:12 +0000 to 2021-08-26 07:04:58 +0000
- Make glossary more linkable and add more detail  (rust-embedded/book#299)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants