diff --git a/Cargo.toml b/Cargo.toml index 38dd5bba..e70ed6a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -350,11 +350,6 @@ path = "examples/tutorial_derive/05_01_assert.rs" required-features = ["derive"] test = true -[[example]] -name = "custom-bool" -path = "examples/derive_ref/custom-bool.rs" -required-features = ["derive"] - [[example]] name = "interop_augment_args" path = "examples/derive_ref/augment_args.rs" diff --git a/examples/derive_ref/custom-bool.md b/examples/derive_ref/custom-bool.md deleted file mode 100644 index 04e3ff0c..00000000 --- a/examples/derive_ref/custom-bool.md +++ /dev/null @@ -1,44 +0,0 @@ -*Jump to [source](custom-bool.rs)* - -Example of overriding the magic `bool` behavior - -```console -$ custom-bool --help -A simple to use, efficient, and full-featured Command Line Argument Parser - -Usage: custom-bool[EXE] [OPTIONS] --foo - -Arguments: - [possible values: true, false] - -Options: - --foo [possible values: true, false] - --bar [default: false] - -h, --help Print help information - -V, --version Print version information - -$ custom-bool -? failed -error: The following required arguments were not provided: - --foo - - -Usage: custom-bool[EXE] --foo - -For more information try '--help' - -$ custom-bool --foo true false -[examples/derive_ref/custom-bool.rs:31] opt = Opt { - foo: true, - bar: false, - boom: false, -} - -$ custom-bool --foo true --bar true false -[examples/derive_ref/custom-bool.rs:31] opt = Opt { - foo: true, - bar: true, - boom: false, -} - -``` diff --git a/examples/derive_ref/custom-bool.rs b/examples/derive_ref/custom-bool.rs deleted file mode 100644 index ee2d6074..00000000 --- a/examples/derive_ref/custom-bool.rs +++ /dev/null @@ -1,32 +0,0 @@ -use clap::Parser; - -#[derive(Parser, Debug, PartialEq)] -#[command(author, version, about, long_about = None)] -struct Opt { - // Default parser for `Set` is FromStr::from_str. - // `impl FromStr for bool` parses `true` or `false` so this - // works as expected. - #[arg(long, action = clap::ArgAction::Set)] - foo: bool, - - // Of course, this could be done with an explicit parser function. - #[arg(long, action = clap::ArgAction::Set, value_parser = true_or_false, default_value_t)] - bar: bool, - - // `bool` can be positional only with explicit `action` annotation - #[arg(action = clap::ArgAction::Set)] - boom: bool, -} - -fn true_or_false(s: &str) -> Result { - match s { - "true" => Ok(true), - "false" => Ok(false), - _ => Err("expected `true` or `false`"), - } -} - -fn main() { - let opt = Opt::parse(); - dbg!(opt); -} diff --git a/src/_derive/mod.rs b/src/_derive/mod.rs index 6be1bfd1..2f5f97a0 100644 --- a/src/_derive/mod.rs +++ b/src/_derive/mod.rs @@ -265,7 +265,6 @@ //! //! Notes: //! - For custom type behavior, you can override the implied attributes/settings and/or set additional ones -//! - For example, see [custom-bool](./custom-bool.md) //! - `Option>` will be `None` instead of `vec![]` if no arguments are provided. //! - This gives the user some flexibility in designing their argument, like with `min_values(0)` //!