mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 15:27:16 +00:00
docs: Stop demonstrating SubcommandRequiredElseHelp
This commit is contained in:
parent
e8e469178c
commit
8f201d8dd6
4 changed files with 11 additions and 10 deletions
|
@ -2,12 +2,13 @@
|
|||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::{arg, App, AppSettings};
|
||||
use clap::{arg, App};
|
||||
|
||||
fn main() {
|
||||
let matches = App::new("git")
|
||||
.about("A fictional versioning CLI")
|
||||
.setting(AppSettings::SubcommandRequiredElseHelp)
|
||||
.subcommand_required(true)
|
||||
.arg_required_else_help(true)
|
||||
.allow_external_subcommands(true)
|
||||
.allow_invalid_utf8_for_external_subcommands(true)
|
||||
.subcommand(
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use clap::{App, AppSettings, Arg};
|
||||
use clap::{App, Arg};
|
||||
|
||||
fn main() {
|
||||
let matches = App::new("pacman")
|
||||
.about("package manager utility")
|
||||
.version("5.2.1")
|
||||
.setting(AppSettings::SubcommandRequiredElseHelp)
|
||||
.subcommand_required(true)
|
||||
.arg_required_else_help(true)
|
||||
.author("Pacman Development Team")
|
||||
// Query subcommand
|
||||
//
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use clap::{app_from_crate, arg, App, AppSettings};
|
||||
use clap::{app_from_crate, arg, App};
|
||||
|
||||
fn main() {
|
||||
let matches = app_from_crate!()
|
||||
.propagate_version(true)
|
||||
.setting(AppSettings::SubcommandRequiredElseHelp)
|
||||
.subcommand_required(true)
|
||||
.arg_required_else_help(true)
|
||||
.subcommand(
|
||||
App::new("add")
|
||||
.about("Adds files to myapp")
|
||||
|
@ -16,8 +17,6 @@ fn main() {
|
|||
"'myapp add' was used, name is: {:?}",
|
||||
sub_matches.value_of("NAME")
|
||||
),
|
||||
_ => unreachable!(
|
||||
"Exhausted list of subcommands and SubcommandRequiredElseHelp prevents `None`"
|
||||
),
|
||||
_ => unreachable!("Exhausted list of subcommands and subcommand_required prevents `None`"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -306,7 +306,7 @@ $ 03_04_subcommands add bob
|
|||
|
||||
```
|
||||
|
||||
Because we set `AppSettings::SubcommandRequiredElseHelp`:
|
||||
Because we set `App::arg_required_else_help`:
|
||||
```console
|
||||
$ 03_04_subcommands
|
||||
? failed
|
||||
|
|
Loading…
Add table
Reference in a new issue