Skip to content

Commit c774a89

Browse files
committed
docs: Reduce main's in doctests
1 parent 73534f6 commit c774a89

6 files changed

Lines changed: 54 additions & 79 deletions

File tree

clap_builder/src/builder/command.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,8 @@ impl Command {
613613
/// cmd().debug_assert();
614614
/// }
615615
///
616-
/// fn main() {
617-
/// let m = cmd().get_matches_from(vec!["foo", "-b"]);
618-
/// println!("{}", m.get_flag("bar"));
619-
/// }
616+
/// let m = cmd().get_matches_from(vec!["foo", "-b"]);
617+
/// println!("{}", m.get_flag("bar"));
620618
/// ```
621619
#[allow(clippy::test_attr_in_doctest)]
622620
pub fn debug_assert(mut self) {

clap_complete/src/aot/generator/mod.rs

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,9 @@ pub trait Generator {
146146
///
147147
/// mod cli;
148148
///
149-
/// fn main() {
150-
/// let _m = cli::build_cli().get_matches();
149+
/// let _m = cli::build_cli().get_matches();
151150
///
152-
/// // normal logic continues...
153-
/// }
151+
/// // normal logic continues...
154152
/// ```
155153
///
156154
/// Next, we set up our `Cargo.toml` to use a `build.rs` build script.
@@ -176,24 +174,22 @@ pub trait Generator {
176174
///
177175
/// include!("src/cli.rs");
178176
///
179-
/// fn main() -> Result<(), Error> {
180-
/// let outdir = match env::var_os("OUT_DIR") {
181-
/// None => return Ok(()),
182-
/// Some(outdir) => outdir,
183-
/// };
177+
/// let outdir = match env::var_os("OUT_DIR") {
178+
/// None => return Ok(()),
179+
/// Some(outdir) => outdir,
180+
/// };
184181
///
185-
/// let mut cmd = build_cli();
186-
/// let path = generate_to(
187-
/// Bash,
188-
/// &mut cmd, // We need to specify what generator to use
189-
/// "myapp", // We need to specify the bin name manually
190-
/// outdir, // We need to specify where to write to
191-
/// )?;
182+
/// let mut cmd = build_cli();
183+
/// let path = generate_to(
184+
/// Bash,
185+
/// &mut cmd, // We need to specify what generator to use
186+
/// "myapp", // We need to specify the bin name manually
187+
/// outdir, // We need to specify where to write to
188+
/// )?;
192189
///
193-
/// println!("cargo:warning=completion file is generated: {path:?}");
190+
/// println!("cargo:warning=completion file is generated: {path:?}");
194191
///
195-
/// Ok(())
196-
/// }
192+
/// Ok(())
197193
/// ```
198194
///
199195
/// Now, once we compile there will be a `{bin_name}.bash` file in the directory.
@@ -218,19 +214,17 @@ pub trait Generator {
218214
///
219215
/// include!("src/cli.rs");
220216
///
221-
/// fn main() -> Result<(), Error> {
222-
/// let outdir = match env::var_os("OUT_DIR") {
223-
/// None => return Ok(()),
224-
/// Some(outdir) => outdir,
225-
/// };
226-
///
227-
/// let mut cmd = build_cli();
228-
/// for &shell in Shell::value_variants() {
229-
/// generate_to(shell, &mut cmd, "myapp", outdir)?;
230-
/// }
217+
/// let outdir = match env::var_os("OUT_DIR") {
218+
/// None => return Ok(()),
219+
/// Some(outdir) => outdir,
220+
/// };
231221
///
232-
/// Ok(())
222+
/// let mut cmd = build_cli();
223+
/// for &shell in Shell::value_variants() {
224+
/// generate_to(shell, &mut cmd, "myapp", outdir)?;
233225
/// }
226+
///
227+
/// Ok(())
234228
/// ```
235229
pub fn generate_to<G, S, T>(
236230
generator: G,
@@ -273,16 +267,13 @@ where
273267
/// use std::io;
274268
/// use clap_complete::{generate, shells::Bash};
275269
///
276-
/// fn main() {
277-
/// let matches = cli::build_cli().get_matches();
278-
///
279-
/// if matches.is_present("generate-bash-completions") {
280-
/// generate(Bash, &mut cli::build_cli(), "myapp", &mut io::stdout());
281-
/// }
270+
/// let matches = cli::build_cli().get_matches();
282271
///
283-
/// // normal logic continues...
272+
/// if matches.is_present("generate-bash-completions") {
273+
/// generate(Bash, &mut cli::build_cli(), "myapp", &mut io::stdout());
284274
/// }
285275
///
276+
/// // normal logic continues...
286277
/// ```
287278
///
288279
/// Usage:

clap_complete/src/aot/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@
3737
//! generate(generator, cmd, cmd.get_name().to_string(), &mut io::stdout());
3838
//! }
3939
//!
40-
//! fn main() {
41-
//! let matches = build_cli().get_matches();
42-
//!
43-
//! if let Some(generator) = matches.get_one::<Shell>("generator").copied() {
44-
//! let mut cmd = build_cli();
45-
//! eprintln!("Generating completion file for {generator}...");
46-
//! print_completions(generator, &mut cmd);
47-
//! }
40+
//! let matches = build_cli().get_matches();
41+
//!
42+
//! if let Some(generator) = matches.get_one::<Shell>("generator").copied() {
43+
//! let mut cmd = build_cli();
44+
//! eprintln!("Generating completion file for {generator}...");
45+
//! print_completions(generator, &mut cmd);
4846
//! }
4947
//! ```
5048

clap_complete/src/env/mod.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
//! # clap::Command::new("empty")
99
//! }
1010
//!
11-
//! fn main() {
12-
//! CompleteEnv::with_factory(cli)
13-
//! .complete();
11+
//! CompleteEnv::with_factory(cli)
12+
//! .complete();
1413
//!
15-
//! // ... rest of application logic
16-
//! }
14+
//! // ... rest of application logic
1715
//! ```
1816
//!
1917
//! To customize completions, see
@@ -92,12 +90,10 @@ pub use shells::*;
9290
/// # clap::Command::new("empty")
9391
/// }
9492
///
95-
/// fn main() {
96-
/// CompleteEnv::with_factory(cli)
97-
/// .complete()
93+
/// CompleteEnv::with_factory(cli)
94+
/// .complete()
9895
///
99-
/// // ... rest of application logic
100-
/// }
96+
/// // ... rest of application logic
10197
/// ```
10298
pub struct CompleteEnv<'s, F> {
10399
factory: F,
@@ -120,12 +116,10 @@ impl<'s, F: Fn() -> clap::Command> CompleteEnv<'s, F> {
120116
/// # clap::Command::new("empty")
121117
/// }
122118
///
123-
/// fn main() {
124-
/// CompleteEnv::with_factory(cli)
125-
/// .complete()
119+
/// CompleteEnv::with_factory(cli)
120+
/// .complete()
126121
///
127-
/// // ... rest of application logic
128-
/// }
122+
/// // ... rest of application logic
129123
/// ```
130124
///
131125
/// Derive:
@@ -139,12 +133,10 @@ impl<'s, F: Fn() -> clap::Command> CompleteEnv<'s, F> {
139133
/// custom: Option<String>,
140134
/// }
141135
///
142-
/// fn main() {
143-
/// CompleteEnv::with_factory(Cli::command)
144-
/// .complete()
136+
/// CompleteEnv::with_factory(Cli::command)
137+
/// .complete()
145138
///
146-
/// // ... rest of application logic
147-
/// }
139+
/// // ... rest of application logic
148140
/// ```
149141
pub fn with_factory(factory: F) -> Self {
150142
Self {

clap_complete/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@
3535
//! generate(generator, cmd, cmd.get_name().to_string(), &mut io::stdout());
3636
//! }
3737
//!
38-
//! fn main() {
39-
//! let matches = build_cli().get_matches();
38+
//! let matches = build_cli().get_matches();
4039
//!
41-
//! if let Some(generator) = matches.get_one::<Shell>("generator").copied() {
42-
//! let mut cmd = build_cli();
43-
//! eprintln!("Generating completion file for {generator}...");
44-
//! print_completions(generator, &mut cmd);
45-
//! }
40+
//! if let Some(generator) = matches.get_one::<Shell>("generator").copied() {
41+
//! let mut cmd = build_cli();
42+
//! eprintln!("Generating completion file for {generator}...");
43+
//! print_completions(generator, &mut cmd);
4644
//! }
4745
//! ```
4846

src/_derive/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@
8181
//! Variant1,
8282
//! }
8383
//!
84-
//! fn main() {
85-
//! let cli = Cli::parse();
86-
//! }
84+
//! let cli = Cli::parse();
8785
//! ```
8886
//!
8987
//! Traits:

0 commit comments

Comments
 (0)