chapter_0.rs |
## Quick Start
You can create an application with several arguments using usage strings.
First, ensure `clap` is available:
```console
$ cargo add clap
```
```rust |
699 |
chapter_1.rs |
## Configuring the Parser
You use [`Command`][crate::Command] to start building a parser.
```rust |
1097 |
chapter_2.rs |
## Adding Arguments
1. [Positionals](#positionals)
2. [Options](#options)
3. [Flags](#flags)
4. [Subcommands](#subcommands)
5. [Defaults](#defaults)
### Positionals
You can have users specify values by their position on the command-line:
```rust |
3154 |
chapter_3.rs |
## Validation
1. [Enumerated values](#enumerated-values)
2. [Validated values](#validated-values)
3. [Argument Relations](#argument-relations)
4. [Custom Validation](#custom-validation)
An appropriate default parser/validator will be selected for the field's type. See
[`value_parser!`][crate::value_parser!] for more details.
### Enumerated values
If you have arguments of specific values you want to test for, you can use the
[`PossibleValuesParser`][crate::builder::PossibleValuesParser] or [`Arg::value_parser(["val1",
...])`][crate::Arg::value_parser] for short.
This allows you specify the valid values for that argument. If the user does not use one of
those specific values, they will receive a graceful exit with error message informing them
of the mistake, and what the possible valid values are
```rust |
3398 |
chapter_4.rs |
## Testing
clap reports most development errors as `debug_assert!`s. Rather than checking every
subcommand, you should have a test that calls
[`Command::debug_assert`][crate::Command::debug_assert]:
```rust,no_run |
491 |
chapter_5.rs |
## Next Steps
- [Cookbook][crate::_cookbook] for application-focused examples
- Explore more features in the [API reference][super]
For support, see [Discussions](https://github.com/clap-rs/clap/discussions) |
368 |
mod.rs |
# Documentation: Builder Tutorial
1. [Quick Start][chapter_0]
2. [Configuring the Parser][chapter_1]
3. [Adding Arguments][chapter_2]
1. [Positionals][chapter_2#positionals]
2. [Options][chapter_2#options]
3. [Flags][chapter_2#flags]
4. [Subcommands][chapter_2#subcommands]
5. [Defaults][chapter_2#defaults]
4. [Validation][chapter_3]
1. [Enumerated values][chapter_3#enumerated-values]
2. [Validated values][chapter_3#validated-values]
3. [Argument Relations][chapter_3#argument-relations]
4. [Custom Validation][chapter_3#custom-validation]
5. [Testing][chapter_4]
6. [Next Steps][chapter_5] |
1195 |