diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ed41849c7bb..9c80815f516 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -77,7 +77,7 @@ Note: We have not yet determined the End-of-Life schedule for previous major ver ### Verifying Changes A common (sub)set of commands for verifying your change: -```sh +```console $ make test-full $ make clippy-full $ make doc diff --git a/clap_complete/examples/completion-derive.rs b/clap_complete/examples/completion-derive.rs index da3a914bf12..9f1a55d7d15 100644 --- a/clap_complete/examples/completion-derive.rs +++ b/clap_complete/examples/completion-derive.rs @@ -1,16 +1,16 @@ //! How to use value hints and generate shell completions. //! //! Usage with zsh: -//! ```sh -//! cargo run --example completion-derive -- --generate=zsh > /usr/local/share/zsh/site-functions/_completion_derive -//! compinit -//! ./target/debug/examples/completion_derive -- +//! ```console +//! $ cargo run --example completion-derive -- --generate=zsh > /usr/local/share/zsh/site-functions/_completion_derive +//! $ compinit +//! $ ./target/debug/examples/completion_derive -- //! ``` //! fish: -//! ```sh -//! cargo run --example completion-derive -- --generate=fish > completion_derive.fish -//! . ./completion_derive.fish -//! ./target/debug/examples/completion_derive -- +//! ```console +//! $ cargo run --example completion-derive -- --generate=fish > completion_derive.fish +//! $ . ./completion_derive.fish +//! $ ./target/debug/examples/completion_derive -- //! ``` use clap::{Args, Command, CommandFactory, Parser, Subcommand, ValueHint}; use clap_complete::{generate, Generator, Shell}; diff --git a/clap_complete/examples/completion.rs b/clap_complete/examples/completion.rs index 4c66610697b..08905425954 100644 --- a/clap_complete/examples/completion.rs +++ b/clap_complete/examples/completion.rs @@ -1,16 +1,16 @@ //! Example to test arguments with different ValueHint values. //! //! Usage with zsh: -//! ```sh -//! cargo run --example completion -- --generate=zsh > /usr/local/share/zsh/site-functions/_completion -//! compinit -//! ./target/debug/examples/completion -- +//! ```console +//! $ cargo run --example completion -- --generate=zsh > /usr/local/share/zsh/site-functions/_completion$ +//! $ compinit +//! $ ./target/debug/examples/completion -- //! ``` //! fish: -//! ```sh -//! cargo run --example completion -- --generate=fish > completion.fish -//! . ./completion.fish -//! ./target/debug/examples/completion -- +//! ```console +//! $ cargo run --example completion -- --generate=fish > completion.fish +//! $ . ./completion.fish +//! $ ./target/debug/examples/completion -- //! ``` use clap::{value_parser, Arg, Command, ValueHint}; use clap_complete::{generate, Generator, Shell}; diff --git a/clap_complete/src/generator/mod.rs b/clap_complete/src/generator/mod.rs index c025697edfa..c766508e019 100644 --- a/clap_complete/src/generator/mod.rs +++ b/clap_complete/src/generator/mod.rs @@ -217,7 +217,7 @@ where /// /// Usage: /// -/// ```shell +/// ```console /// $ myapp generate-bash-completions > /usr/share/bash-completion/completions/myapp.bash /// ``` pub fn generate(gen: G, cmd: &mut clap::Command, bin_name: S, buf: &mut dyn Write) diff --git a/src/builder/action.rs b/src/builder/action.rs index 9739f8800b9..6f4c6b030c3 100644 --- a/src/builder/action.rs +++ b/src/builder/action.rs @@ -2,8 +2,8 @@ /// /// # Examples /// -#[cfg_attr(not(feature = "help"), doc = " ```ignore")] -#[cfg_attr(feature = "help", doc = " ```")] +/// ```rust +/// # #[cfg(feature = "help")] { /// # use clap::Command; /// # use clap::Arg; /// let cmd = Command::new("mycmd") @@ -20,6 +20,7 @@ /// // New help available /// let err = cmd.try_get_matches_from(["mycmd", "-?"]).unwrap_err(); /// assert_eq!(err.kind(), clap::error::ErrorKind::DisplayHelp); +/// # } /// ``` #[derive(Clone, Debug)] #[non_exhaustive] @@ -224,8 +225,8 @@ pub enum ArgAction { /// /// # Examples /// - #[cfg_attr(not(feature = "help"), doc = " ```ignore")] - #[cfg_attr(feature = "help", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "help")] { /// # use clap::Command; /// # use clap::Arg; /// let cmd = Command::new("mycmd") @@ -242,6 +243,7 @@ pub enum ArgAction { /// // New help available /// let err = cmd.try_get_matches_from(["mycmd", "-?"]).unwrap_err(); /// assert_eq!(err.kind(), clap::error::ErrorKind::DisplayHelp); + /// # } /// ``` Help, /// When encountered, display [`Command::version`][super::Command::version] diff --git a/src/builder/arg.rs b/src/builder/arg.rs index bf898cbfd64..8992d0bb080 100644 --- a/src/builder/arg.rs +++ b/src/builder/arg.rs @@ -1125,8 +1125,8 @@ impl Arg { /// # ; /// ``` /// - #[cfg_attr(not(feature = "help"), doc = " ```ignore")] - #[cfg_attr(feature = "help", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "help")] { /// # use clap::{Command, Arg}; /// let m = Command::new("prog") /// .arg(Arg::new("config") @@ -1136,6 +1136,7 @@ impl Arg { /// .get_matches_from(vec![ /// "prog", "--help" /// ]); + /// # } /// ``` /// Running the above program produces the following output /// @@ -1187,8 +1188,8 @@ impl Arg { /// .value_names(["fast", "slow"]); /// ``` /// - #[cfg_attr(not(feature = "help"), doc = " ```ignore")] - #[cfg_attr(feature = "help", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "help")] { /// # use clap::{Command, Arg}; /// let m = Command::new("prog") /// .arg(Arg::new("io") @@ -1197,6 +1198,7 @@ impl Arg { /// .get_matches_from(vec![ /// "prog", "--help" /// ]); + /// # } /// ``` /// /// Running the above program produces the following output @@ -2013,8 +2015,8 @@ impl Arg { /// Setting `help` displays a short message to the side of the argument when the user passes /// `-h` or `--help` (by default). /// - #[cfg_attr(not(feature = "help"), doc = " ```ignore")] - #[cfg_attr(feature = "help", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "help")] { /// # use clap::{Command, Arg}; /// let m = Command::new("prog") /// .arg(Arg::new("cfg") @@ -2023,6 +2025,7 @@ impl Arg { /// .get_matches_from(vec![ /// "prog", "--help" /// ]); + /// # } /// ``` /// /// The above example displays @@ -2063,8 +2066,8 @@ impl Arg { /// Setting `help` displays a short message to the side of the argument when the user passes /// `-h` or `--help` (by default). /// - #[cfg_attr(not(feature = "help"), doc = " ```ignore")] - #[cfg_attr(feature = "help", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "help")] { /// # use clap::{Command, Arg}; /// let m = Command::new("prog") /// .arg(Arg::new("cfg") @@ -2077,6 +2080,7 @@ impl Arg { /// .get_matches_from(vec![ /// "prog", "--help" /// ]); + /// # } /// ``` /// /// The above example displays @@ -2121,8 +2125,8 @@ impl Arg { /// /// # Examples /// - #[cfg_attr(not(feature = "help"), doc = " ```ignore")] - #[cfg_attr(feature = "help", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "help")] { /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("a") // Typically args are grouped alphabetically by name. @@ -2144,6 +2148,7 @@ impl Arg { /// .get_matches_from(vec![ /// "prog", "--help" /// ]); + /// # } /// ``` /// /// The above example displays the following help message @@ -2188,8 +2193,8 @@ impl Arg { /// /// # Examples /// - #[cfg_attr(not(feature = "help"), doc = " ```ignore")] - #[cfg_attr(feature = "help", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "help")] { /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("opt") @@ -2204,6 +2209,7 @@ impl Arg { /// .get_matches_from(vec![ /// "prog", "--help" /// ]); + /// # } /// ``` /// /// The above example displays the following help message @@ -2239,8 +2245,8 @@ impl Arg { /// /// Setting `Hidden` will hide the argument when displaying help text /// - #[cfg_attr(not(feature = "help"), doc = " ```ignore")] - #[cfg_attr(feature = "help", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "help")] { /// # use clap::{Command, Arg}; /// let m = Command::new("prog") /// .arg(Arg::new("cfg") @@ -2250,6 +2256,7 @@ impl Arg { /// .get_matches_from(vec![ /// "prog", "--help" /// ]); + /// # } /// ``` /// /// The above example displays @@ -2413,8 +2420,8 @@ impl Arg { /// /// Setting `hide_short_help(true)` will hide the argument when displaying short help text /// - #[cfg_attr(not(feature = "help"), doc = " ```ignore")] - #[cfg_attr(feature = "help", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "help")] { /// # use clap::{Command, Arg}; /// let m = Command::new("prog") /// .arg(Arg::new("cfg") @@ -2424,6 +2431,7 @@ impl Arg { /// .get_matches_from(vec![ /// "prog", "-h" /// ]); + /// # } /// ``` /// /// The above example displays @@ -2440,8 +2448,8 @@ impl Arg { /// /// However, when --help is called /// - #[cfg_attr(not(feature = "help"), doc = " ```ignore")] - #[cfg_attr(feature = "help", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "help")] { /// # use clap::{Command, Arg}; /// let m = Command::new("prog") /// .arg(Arg::new("cfg") @@ -2451,6 +2459,7 @@ impl Arg { /// .get_matches_from(vec![ /// "prog", "--help" /// ]); + /// # } /// ``` /// /// Then the following would be displayed @@ -2486,8 +2495,8 @@ impl Arg { /// /// Setting `hide_long_help(true)` will hide the argument when displaying long help text /// - #[cfg_attr(not(feature = "help"), doc = " ```ignore")] - #[cfg_attr(feature = "help", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "help")] { /// # use clap::{Command, Arg}; /// let m = Command::new("prog") /// .arg(Arg::new("cfg") @@ -2497,6 +2506,7 @@ impl Arg { /// .get_matches_from(vec![ /// "prog", "--help" /// ]); + /// # } /// ``` /// /// The above example displays @@ -2513,8 +2523,8 @@ impl Arg { /// /// However, when -h is called /// - #[cfg_attr(not(feature = "help"), doc = " ```ignore")] - #[cfg_attr(feature = "help", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "help")] { /// # use clap::{Command, Arg}; /// let m = Command::new("prog") /// .arg(Arg::new("cfg") @@ -2524,6 +2534,7 @@ impl Arg { /// .get_matches_from(vec![ /// "prog", "-h" /// ]); + /// # } /// ``` /// /// Then the following would be displayed diff --git a/src/builder/command.rs b/src/builder/command.rs index 635aa1bcd57..f76c40cfd47 100644 --- a/src/builder/command.rs +++ b/src/builder/command.rs @@ -2608,8 +2608,8 @@ impl Command { /// /// # Examples /// - #[cfg_attr(not(feature = "help"), doc = " ```ignore")] - #[cfg_attr(feature = "help", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "help")] { /// # use clap::{Command, }; /// let m = Command::new("cust-ord") /// .subcommand(Command::new("alpha") // typically subcommands are grouped @@ -2627,6 +2627,7 @@ impl Command { /// .get_matches_from(vec![ /// "cust-ord", "--help" /// ]); + /// # } /// ``` /// /// The above example displays the following help message @@ -2756,8 +2757,8 @@ impl Command { /// /// # Examples /// - #[cfg_attr(not(unix), doc = " ```ignore")] - #[cfg_attr(unix, doc = " ```")] + /// ```rust + /// # #[cfg(unix)] { /// # use std::ffi::OsString; /// # use clap::Command; /// # use clap::value_parser; @@ -2778,6 +2779,7 @@ impl Command { /// }, /// _ => {}, /// } + /// # } /// ``` /// /// ``` diff --git a/src/builder/value_parser.rs b/src/builder/value_parser.rs index 191e8ae76c4..3d2643938c2 100644 --- a/src/builder/value_parser.rs +++ b/src/builder/value_parser.rs @@ -166,8 +166,8 @@ impl ValueParser { /// /// # Example /// - #[cfg_attr(not(unix), doc = " ```ignore")] - #[cfg_attr(unix, doc = " ```rust")] + /// ```rust + /// # #[cfg(unix)] { /// # use clap::{Command, Arg, builder::ValueParser}; /// use std::ffi::OsString; /// use std::os::unix::ffi::{OsStrExt,OsStringExt}; @@ -187,6 +187,7 @@ impl ValueParser { /// let arg: &OsString = m.get_one("arg") /// .expect("required"); /// assert_eq!(arg.as_bytes(), &[0xe9]); + /// # } /// ``` pub const fn os_string() -> Self { Self(ValueParserInner::OsString) @@ -644,8 +645,8 @@ where /// /// # Example /// -#[cfg_attr(not(feature = "error-context"), doc = " ```ignore")] -#[cfg_attr(feature = "error-context", doc = " ```")] +/// ```rust +/// # #[cfg(feature = "error-context")] { /// # use clap::error::ErrorKind; /// # use clap::error::ContextKind; /// # use clap::error::ContextValue; @@ -681,6 +682,7 @@ where /// Ok(Custom(val)) /// } /// } +/// # } /// ``` pub trait TypedValueParser: Clone + Send + Sync + 'static { /// Argument's value type diff --git a/src/derive.rs b/src/derive.rs index 98bb0121b6e..3ad72766d48 100644 --- a/src/derive.rs +++ b/src/derive.rs @@ -30,8 +30,8 @@ use std::ffi::OsString; /// throughout the application representing the normalized values coming from /// the CLI. /// -#[cfg_attr(not(feature = "derive"), doc = " ```ignore")] -#[cfg_attr(feature = "derive", doc = " ```")] +/// ```rust +/// # #[cfg(feature = "derive")] { /// /// My super CLI /// #[derive(clap::Parser)] /// #[command(name = "demo")] @@ -43,6 +43,7 @@ use std::ffi::OsString; /// #[arg(short, long)] /// name: Option, /// } +/// # } /// ``` /// /// The equivalent [`Command`] struct + `From` implementation: @@ -179,19 +180,20 @@ pub trait FromArgMatches: Sized { /// Motivation: If our application had two CLI options, `--name /// ` and the flag `--debug`, we may create a struct as follows: /// - #[cfg_attr(not(feature = "derive"), doc = " ```ignore")] - #[cfg_attr(feature = "derive", doc = " ```no_run")] + /// ```rust + /// # #[cfg(feature = "derive")] { /// struct Context { /// name: String, /// debug: bool /// } + /// # } /// ``` /// /// We then need to convert the `ArgMatches` that `clap` generated into our struct. /// `from_arg_matches` serves as the equivalent of: /// - #[cfg_attr(not(feature = "derive"), doc = " ```ignore")] - #[cfg_attr(feature = "derive", doc = " ```no_run")] + /// ```rust + /// # #[cfg(feature = "derive")] { /// # use clap::ArgMatches; /// # struct Context { /// # name: String, @@ -205,6 +207,7 @@ pub trait FromArgMatches: Sized { /// } /// } /// } + /// # } /// ``` fn from_arg_matches(matches: &ArgMatches) -> Result; @@ -213,19 +216,20 @@ pub trait FromArgMatches: Sized { /// Motivation: If our application had two CLI options, `--name /// ` and the flag `--debug`, we may create a struct as follows: /// - #[cfg_attr(not(feature = "derive"), doc = " ```ignore")] - #[cfg_attr(feature = "derive", doc = " ```no_run")] + /// ```rust + /// # #[cfg(feature = "derive")] { /// struct Context { /// name: String, /// debug: bool /// } + /// # } /// ``` /// /// We then need to convert the `ArgMatches` that `clap` generated into our struct. /// `from_arg_matches_mut` serves as the equivalent of: /// - #[cfg_attr(not(feature = "derive"), doc = " ```ignore")] - #[cfg_attr(feature = "derive", doc = " ```no_run")] + /// ```rust + /// # #[cfg(feature = "derive")] { /// # use clap::ArgMatches; /// # struct Context { /// # name: String, @@ -239,6 +243,7 @@ pub trait FromArgMatches: Sized { /// } /// } /// } + /// # } /// ``` fn from_arg_matches_mut(matches: &mut ArgMatches) -> Result { Self::from_arg_matches(matches) @@ -267,8 +272,8 @@ pub trait FromArgMatches: Sized { /// /// # Example /// -#[cfg_attr(not(feature = "derive"), doc = " ```ignore")] -#[cfg_attr(feature = "derive", doc = " ```")] +/// ```rust +/// # #[cfg(feature = "derive")] { /// #[derive(clap::Parser)] /// struct Args { /// #[command(flatten)] @@ -280,6 +285,7 @@ pub trait FromArgMatches: Sized { /// #[arg(long, short = 'v', action = clap::ArgAction::Count)] /// verbose: u8, /// } +/// # } /// ``` pub trait Args: FromArgMatches + Sized { /// Report the [`ArgGroup::id`][crate::ArgGroup::id] for this set of arguments @@ -313,8 +319,8 @@ pub trait Args: FromArgMatches + Sized { /// /// # Example /// -#[cfg_attr(not(feature = "derive"), doc = " ```ignore")] -#[cfg_attr(feature = "derive", doc = " ```")] +/// ```rust +/// # #[cfg(feature = "derive")] { /// #[derive(clap::Parser)] /// struct Args { /// #[command(subcommand)] @@ -326,6 +332,7 @@ pub trait Args: FromArgMatches + Sized { /// Add, /// Remove, /// } +/// # } /// ``` pub trait Subcommand: FromArgMatches + Sized { /// Append to [`Command`] so it can instantiate `Self`. @@ -355,8 +362,8 @@ pub trait Subcommand: FromArgMatches + Sized { /// /// # Example /// -#[cfg_attr(not(feature = "derive"), doc = " ```ignore")] -#[cfg_attr(feature = "derive", doc = " ```")] +/// ```rust +/// # #[cfg(feature = "derive")] { /// #[derive(clap::Parser)] /// struct Args { /// #[arg(value_enum)] @@ -370,6 +377,7 @@ pub trait Subcommand: FromArgMatches + Sized { /// Warning, /// Error, /// } +/// # } /// ``` pub trait ValueEnum: Sized + Clone { /// All possible argument values, in display order. diff --git a/src/error/kind.rs b/src/error/kind.rs index 1859237a25a..55fac3b973f 100644 --- a/src/error/kind.rs +++ b/src/error/kind.rs @@ -39,8 +39,8 @@ pub enum ErrorKind { /// /// # Examples /// - #[cfg_attr(not(feature = "suggestions"), doc = " ```no_run")] - #[cfg_attr(feature = "suggestions", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "suggestions")] { /// # use clap::{Command, Arg, error::ErrorKind, }; /// let result = Command::new("prog") /// .subcommand(Command::new("config") @@ -50,6 +50,7 @@ pub enum ErrorKind { /// .try_get_matches_from(vec!["prog", "confi"]); /// assert!(result.is_err()); /// assert_eq!(result.unwrap_err().kind(), ErrorKind::InvalidSubcommand); + /// # } /// ``` /// /// [`Subcommand`]: crate::Subcommand @@ -222,8 +223,8 @@ pub enum ErrorKind { /// /// # Examples /// - #[cfg_attr(not(unix), doc = " ```ignore")] - #[cfg_attr(unix, doc = " ```")] + /// ```rust + /// # #[cfg(unix)] { /// # use clap::{Command, Arg, error::ErrorKind, ArgAction}; /// # use std::os::unix::ffi::OsStringExt; /// # use std::ffi::OsString; @@ -236,6 +237,7 @@ pub enum ErrorKind { /// OsString::from_vec(vec![0xE9])]); /// assert!(result.is_err()); /// assert_eq!(result.unwrap_err().kind(), ErrorKind::InvalidUtf8); + /// # } /// ``` /// /// [`Arg::allow_invalid_utf8`]: crate::Arg::allow_invalid_utf8 @@ -250,13 +252,14 @@ pub enum ErrorKind { /// /// # Examples /// - #[cfg_attr(not(feature = "help"), doc = " ```ignore")] - #[cfg_attr(feature = "help", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "help")] { /// # use clap::{Command, Arg, error::ErrorKind}; /// let result = Command::new("prog") /// .try_get_matches_from(vec!["prog", "--help"]); /// assert!(result.is_err()); /// assert_eq!(result.unwrap_err().kind(), ErrorKind::DisplayHelp); + /// # } /// ``` DisplayHelp, diff --git a/src/error/mod.rs b/src/error/mod.rs index 2d8bf62e47c..84c50ea916a 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -106,8 +106,8 @@ impl Error { /// /// # Example /// - #[cfg_attr(not(feature = "error-context"), doc = " ```ignore")] - #[cfg_attr(feature = "error-context", doc = " ```")] + /// ```rust + /// # #[cfg(feature = "error-context")] { /// # use clap::error::ErrorKind; /// # use clap::error::ContextKind; /// # use clap::error::ContextValue; @@ -120,6 +120,7 @@ impl Error { /// err.insert(ContextKind::InvalidValue, ContextValue::String("bar".to_owned())); /// /// err.print(); + /// # } /// ``` pub fn new(kind: ErrorKind) -> Self { Self { diff --git a/src/lib.rs b/src/lib.rs index ab2d9d4754c..c70c1c2672c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,9 +41,10 @@ //! *(See also [feature flag reference][_features])* //! //! Then define your CLI in `main.rs`: -#![cfg_attr(not(feature = "derive"), doc = " ```ignore")] -#![cfg_attr(feature = "derive", doc = " ```no_run")] +//! ```rust +//! # #[cfg(feature = "derive")] { #![doc = include_str!("../examples/demo.rs")] +//! # } //! ``` //! //! And try it out: diff --git a/src/output/help_template.rs b/src/output/help_template.rs index e84cd727c79..606dccbfefe 100644 --- a/src/output/help_template.rs +++ b/src/output/help_template.rs @@ -234,6 +234,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { } /// Writes binary name of a Parser Object to the wrapped stream. + #[cfg(not(feature = "unstable-v5"))] fn write_bin_name(&mut self) { debug!("HelpTemplate::write_bin_name"); diff --git a/src/parser/matches/arg_matches.rs b/src/parser/matches/arg_matches.rs index 67d2918d0bd..4ca5c80bad7 100644 --- a/src/parser/matches/arg_matches.rs +++ b/src/parser/matches/arg_matches.rs @@ -276,8 +276,8 @@ impl ArgMatches { /// /// # Examples /// - #[cfg_attr(not(unix), doc = " ```ignore")] - #[cfg_attr(unix, doc = " ```")] + /// ```rust + /// # #[cfg(unix)] { /// # use clap::{Command, arg, value_parser}; /// # use std::ffi::{OsStr,OsString}; /// # use std::os::unix::ffi::{OsStrExt,OsStringExt}; @@ -297,6 +297,7 @@ impl ArgMatches { /// assert_eq!(itr.next(), Some(OsStr::new("Hi"))); /// assert_eq!(itr.next(), Some(OsStr::from_bytes(&[0xe9, b'!']))); /// assert_eq!(itr.next(), None); + /// # } /// ``` /// [`Iterator`]: std::iter::Iterator /// [`OsSt`]: std::ffi::OsStr @@ -324,8 +325,8 @@ impl ArgMatches { /// /// # Examples /// - #[cfg_attr(not(unix), doc = " ```ignore")] - #[cfg_attr(unix, doc = " ```")] + /// ```rust + /// # #[cfg(unix)] { /// # use clap::{Command, arg, value_parser, ArgAction, Arg}; /// # use std::ffi::{OsStr,OsString}; /// # use std::os::unix::ffi::{OsStrExt,OsStringExt}; @@ -350,6 +351,7 @@ impl ArgMatches { /// assert_eq!(itr.next(), Some(vec![OsStr::new("a"), OsStr::new("b")])); /// assert_eq!(itr.next(), Some(vec![OsStr::new("c"), OsStr::from_bytes(&[0xe9, b'!'])])); /// assert_eq!(itr.next(), None); + /// # } /// ``` /// [`Iterator`]: std::iter::Iterator /// [`OsStr`]: std::ffi::OsStr @@ -1508,8 +1510,8 @@ impl<'a, T: 'a> Default for ValuesRef<'a, T> { /// /// # Examples /// -#[cfg_attr(not(unix), doc = " ```ignore")] -#[cfg_attr(unix, doc = " ```")] +/// ```rust +/// # #[cfg(unix)] { /// # use clap::{Command, arg, value_parser}; /// use std::ffi::OsString; /// use std::os::unix::ffi::{OsStrExt,OsStringExt}; @@ -1527,6 +1529,7 @@ impl<'a, T: 'a> Default for ValuesRef<'a, T> { /// .as_bytes(), /// [b'H', b'i', b' ', 0xe9, b'!'] /// ); +/// # } /// ``` #[derive(Clone, Debug)] pub struct RawValues<'a> { diff --git a/src/util/color.rs b/src/util/color.rs index 5a0a8ce6d69..4c583cb386a 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -14,12 +14,13 @@ pub enum ColorChoice { /// /// # Examples /// - #[cfg_attr(not(feature = "color"), doc = " ```ignore")] - #[cfg_attr(feature = "color", doc = " ```no_run")] + /// ```rust + /// # #[cfg(feature = "color")] { /// # use clap::{Command, ColorChoice}; /// Command::new("myprog") /// .color(ColorChoice::Auto) /// .get_matches(); + /// # } /// ``` Auto, @@ -31,12 +32,13 @@ pub enum ColorChoice { /// /// # Examples /// - #[cfg_attr(not(feature = "color"), doc = " ```ignore")] - #[cfg_attr(feature = "color", doc = " ```no_run")] + /// ```rust + /// # #[cfg(feature = "color")] { /// # use clap::{Command, ColorChoice}; /// Command::new("myprog") /// .color(ColorChoice::Always) /// .get_matches(); + /// # } /// ``` Always, @@ -48,12 +50,13 @@ pub enum ColorChoice { /// /// # Examples /// - #[cfg_attr(not(feature = "color"), doc = " ```ignore")] - #[cfg_attr(feature = "color", doc = " ```no_run")] + /// ```rust + /// # #[cfg(feature = "color")] { /// # use clap::{Command, ColorChoice}; /// Command::new("myprog") /// .color(ColorChoice::Never) /// .get_matches(); + /// # } /// ``` Never, }