mirror of
https://github.com/clap-rs/clap
synced 2024-12-12 13:52:34 +00:00
docs(tutorial): Focus on actions, not macros
This commit is contained in:
parent
6aa4f90609
commit
78b2b44b95
7 changed files with 20 additions and 15 deletions
|
@ -1,8 +1,13 @@
|
|||
use clap::{arg, command, ArgAction};
|
||||
use clap::{command, Arg, ArgAction};
|
||||
|
||||
fn main() {
|
||||
let matches = command!() // requires `cargo` feature
|
||||
.arg(arg!(-v - -verbose).action(ArgAction::Count))
|
||||
.arg(
|
||||
Arg::new("verbose")
|
||||
.short('v')
|
||||
.long("verbose")
|
||||
.action(ArgAction::Count),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
println!(
|
||||
|
|
|
@ -7,7 +7,7 @@ USAGE:
|
|||
03_02_option[EXE] [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-n, --name <NAME>
|
||||
-n, --name <name>
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use clap::{arg, command};
|
||||
use clap::{command, Arg};
|
||||
|
||||
fn main() {
|
||||
let matches = command!() // requires `cargo` feature
|
||||
.arg(arg!(-n --name <NAME>).required(false))
|
||||
.arg(Arg::new("name").short('n').long("name"))
|
||||
.get_matches();
|
||||
|
||||
println!("name: {:?}", matches.get_one::<String>("name"));
|
||||
|
|
|
@ -4,19 +4,19 @@ clap [..]
|
|||
A simple to use, efficient, and full-featured Command Line Argument Parser
|
||||
|
||||
USAGE:
|
||||
03_03_positional[EXE] [NAME]
|
||||
03_03_positional[EXE] [name]
|
||||
|
||||
ARGS:
|
||||
<NAME>
|
||||
<name>
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
$ 03_03_positional
|
||||
NAME: None
|
||||
name: None
|
||||
|
||||
$ 03_03_positional bob
|
||||
NAME: Some("bob")
|
||||
name: Some("bob")
|
||||
|
||||
```
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use clap::{arg, command};
|
||||
use clap::{command, Arg};
|
||||
|
||||
fn main() {
|
||||
let matches = command!() // requires `cargo` feature
|
||||
.arg(arg!([NAME]))
|
||||
.arg(Arg::new("name"))
|
||||
.get_matches();
|
||||
|
||||
println!("NAME: {:?}", matches.get_one::<String>("NAME"));
|
||||
println!("name: {:?}", matches.get_one::<String>("name"));
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ OPTIONS:
|
|||
-V, --version Print version information
|
||||
|
||||
$ 03_05_default_values
|
||||
NAME: "alice"
|
||||
name: "alice"
|
||||
|
||||
$ 03_05_default_values bob
|
||||
NAME: "bob"
|
||||
name: "bob"
|
||||
|
||||
```
|
||||
|
|
|
@ -6,7 +6,7 @@ fn main() {
|
|||
.get_matches();
|
||||
|
||||
println!(
|
||||
"NAME: {:?}",
|
||||
"name: {:?}",
|
||||
matches
|
||||
.get_one::<String>("NAME")
|
||||
.expect("default ensures there is always a value")
|
||||
|
|
Loading…
Reference in a new issue