clap/examples/13_enum_values.md
Ed Page bfa02fd418 test: More thoroughly test examples
This ports our example testing over to [trycmd](https://docs.rs/) so
we can:
- More thoroughly test our examples
- Provide always-up-to-date example usage

The old way of testing automatically picked up examples.  This new way
requires we have a `.md` file that uses the example in some way.

Notes:
- Moved overall example description to the `.md` file
- I added cross-linking between related examples
- `14_groups` had a redundant paragraph (twice talked about "one and
  only one"
2021-11-23 13:13:41 -06:00

803 B

Building on 11_only_specific_values, we will create an enum with 4 values, assign a positional argument that accepts only one of those values, and use clap to parse the argument.

$ 13_enum_values Foo
Found a Foo
$ 13_enum_values Bar
Found a Bar

Anything else will error, guiding the user to a valid value:

$ 13_enum_values Alice
? failed
error: "Alice" isn't a valid value for '<type>'
	[possible values: Bar, Baz, Foo, Qux]

USAGE:
    13_enum_values[EXE] <type>

For more information try --help

Valid values also get shown in the help:

$ 13_enum_values --help
myapp 

USAGE:
    13_enum_values[EXE] <type>

ARGS:
    <type>    The type to use [possible values: Foo, Bar, Baz, Qux]

OPTIONS:
    -h, --help    Print help information