diff --git a/src/bin/cargo/commands/doc.rs b/src/bin/cargo/commands/doc.rs index 009bd2bfa34..875cfcfcc46 100644 --- a/src/bin/cargo/commands/doc.rs +++ b/src/bin/cargo/commands/doc.rs @@ -20,10 +20,12 @@ pub fn cli() -> App { .arg(opt("no-deps", "Don't build documentation for dependencies")) .arg(opt("document-private-items", "Document private items")) .arg_jobs() - .arg_targets_lib_bin( + .arg_targets_lib_bin_example( "Document only this package's library", "Document only the specified binary", "Document all binaries", + "Document only the specified example", + "Document all examples", ) .arg_release("Build artifacts in release mode, with optimizations") .arg_profile("Build artifacts with the specified profile") diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 9e893928850..c99b8688f1e 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -87,9 +87,7 @@ pub trait AppExt: Sized { benches: &'static str, all: &'static str, ) -> Self { - self.arg_targets_lib_bin(lib, bin, bins) - ._arg(optional_multi_opt("example", "NAME", example)) - ._arg(opt("examples", examples)) + self.arg_targets_lib_bin_example(lib, bin, bins, example, examples) ._arg(optional_multi_opt("test", "NAME", test)) ._arg(opt("tests", tests)) ._arg(optional_multi_opt("bench", "NAME", bench)) @@ -97,10 +95,19 @@ pub trait AppExt: Sized { ._arg(opt("all-targets", all)) } - fn arg_targets_lib_bin(self, lib: &'static str, bin: &'static str, bins: &'static str) -> Self { + fn arg_targets_lib_bin_example( + self, + lib: &'static str, + bin: &'static str, + bins: &'static str, + example: &'static str, + examples: &'static str, + ) -> Self { self._arg(opt("lib", lib)) ._arg(optional_multi_opt("bin", "NAME", bin)) ._arg(opt("bins", bins)) + ._arg(optional_multi_opt("example", "NAME", example)) + ._arg(opt("examples", examples)) } fn arg_targets_bins_examples( diff --git a/src/doc/man/cargo-doc.md b/src/doc/man/cargo-doc.md index d7c3dc7299c..b0289a8368f 100644 --- a/src/doc/man/cargo-doc.md +++ b/src/doc/man/cargo-doc.md @@ -52,6 +52,16 @@ flag and will always document the given target. {{#options}} {{> options-targets-lib-bin }} + +{{#option "`--example` _name_..." }} +{{actionverb}} the specified example. This flag may be specified multiple times +and supports common Unix glob patterns. +{{/option}} + +{{#option "`--examples`" }} +{{actionverb}} all example targets. +{{/option}} + {{/options}} {{> section-features }} diff --git a/src/doc/man/generated_txt/cargo-doc.txt b/src/doc/man/generated_txt/cargo-doc.txt index 2b34fb93fc7..de1589d6304 100644 --- a/src/doc/man/generated_txt/cargo-doc.txt +++ b/src/doc/man/generated_txt/cargo-doc.txt @@ -82,6 +82,13 @@ OPTIONS --bins Document all binary targets. + --example name... + Document the specified example. This flag may be specified multiple + times and supports common Unix glob patterns. + + --examples + Document all example targets. + Feature Selection The feature flags allow you to control which features are enabled. When no feature options are given, the default feature is activated for every diff --git a/src/doc/src/commands/cargo-doc.md b/src/doc/src/commands/cargo-doc.md index 6f8255ca3ab..774169816c9 100644 --- a/src/doc/src/commands/cargo-doc.md +++ b/src/doc/src/commands/cargo-doc.md @@ -107,6 +107,16 @@ and supports common Unix glob patterns.
--example
name...--examples