Loading tutorials
Cargo.toml file. Basic Rust (structs, Option, Result) is enough for the4 min readOption, Result, ownership), can create and run a Cargo project, and have used command-line programs with flags and exit codes. It builds on the previous chapter, where you added clap to Cargo.toml with the derive feature. Here you define a C4 min readOption and Vec, and run a Cargo project. It also assumes you have clap = { version = "4", features = ["derive"] } in Cargo.toml and have seen a #[derive(Parser)] struct before.5 min read#[derive(Parser)] struct as in the previous chapters, that you know Option<T> and Vec<T>, and that you have a project with `clap = { version = "4", fe5 min read#[derive(Parser)], including doc comments on fields and the #[arg(...)] attribute. It also assumes you know that --help exits with status 0. Here you will see where clap gets each line of its help text, how short and long help differ, and how to c5 min read#[derive(Parser)] struct with positional arguments and options, and that you are comfortable with FromStr, Result, and Option. Here you will see how clap turns the raw text of each argument into a typed field, how to tighten that conversion, and how to s4 min readString field accepts any text. If your tool supports only three output formats, a typo like --format jsno reaches your own code, and you must check for it by hand. A restricted argument moves that check into clap. Clap rejects bad input before main continues, prints the allowed values, and e4 min read#[derive(Parser)] and that you know how options, flags and value_parser work. It covers what a program does when the user leaves an option out: use a built-in default, read an environment variable, or fail.5 min read--quiet --verbose makes no sense, and --compress means nothing without --output. This chapter covers how clap enforces these rules before your program logic runs. It assumes you can already define a derived Parser with4 min read#[derive(Parser)] struct with positional arguments, options, and flags. It also assumes you know how ValueEnum restricts a value. Here you will split one program into several commands, as git add and git commit do, and share options across them.4 min readParser, read typed fields, and use Result and ? in Rust. It also assumes you know that a shell reads a program's exit status from $?. Here you will separate the errors clap reports from the errors your program reports. You will also choose exit c4 min read#[derive(Parser)], write a Subcommand enum, and return an ExitCode from main. Those topics come from the earlier chapters on subcommands and error handling.4 min readValueEnum arguments, and that you can run cargo test. You should also know that a process exit code of 0 means success.4 min read#[derive(Parser)], Subcommand, and value_parser. It also assumes you are comfortable with Option, Result, and borrowing. The derive API is the right default. The builder API is what derive generates underneath, and you need to know4 min read