Skip to content

Commit

Permalink
docs: Update to new command! macro
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 15, 2022
1 parent e839e6e commit 4eb269e
Show file tree
Hide file tree
Showing 23 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion examples/cargo-example.rs
Expand Up @@ -5,7 +5,7 @@ fn main() {
.bin_name("cargo")
.subcommand_required(true)
.subcommand(
clap::app_from_crate!().name("example").arg(
clap::command!("example").arg(
clap::arg!(--"manifest-path" <PATH>)
.required(false)
.allow_invalid_utf8(true),
Expand Down
4 changes: 2 additions & 2 deletions examples/escaped-positional.rs
@@ -1,9 +1,9 @@
// Note: this requires the `cargo` feature

use clap::{app_from_crate, arg};
use clap::{arg, command};

fn main() {
let matches = app_from_crate!()
let matches = command!()
.arg(arg!(eff: -f))
.arg(arg!(pea: -p <PEAR>).required(false))
.arg(
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/01_quick.rs
@@ -1,8 +1,8 @@
use clap::{app_from_crate, arg, Command};
use clap::{arg, command, Command};
use std::path::Path;

fn main() {
let matches = app_from_crate!()
let matches = command!()
.arg(arg!([name] "Optional name to operate on"))
.arg(
arg!(
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/02_app_settings.rs
@@ -1,7 +1,7 @@
use clap::{app_from_crate, arg, AppSettings};
use clap::{arg, command, AppSettings};

fn main() {
let matches = app_from_crate!()
let matches = command!()
.args_override_self(true)
.global_setting(AppSettings::DeriveDisplayOrder)
.allow_negative_numbers(true)
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/02_crate.rs
@@ -1,7 +1,7 @@
use clap::{app_from_crate, arg};
use clap::{arg, command};

fn main() {
let matches = app_from_crate!()
let matches = command!()
.arg(arg!(--two <VALUE>))
.arg(arg!(--one <VALUE>))
.get_matches();
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/03_01_flag_bool.rs
@@ -1,7 +1,7 @@
use clap::{app_from_crate, arg};
use clap::{arg, command};

fn main() {
let matches = app_from_crate!().arg(arg!(-v - -verbose)).get_matches();
let matches = command!().arg(arg!(-v - -verbose)).get_matches();

println!("verbose: {:?}", matches.is_present("verbose"));
}
4 changes: 2 additions & 2 deletions examples/tutorial_builder/03_01_flag_count.rs
@@ -1,7 +1,7 @@
use clap::{app_from_crate, arg};
use clap::{arg, command};

fn main() {
let matches = app_from_crate!().arg(arg!(-v --verbose ...)).get_matches();
let matches = command!().arg(arg!(-v --verbose ...)).get_matches();

println!("verbose: {:?}", matches.occurrences_of("verbose"));
}
4 changes: 2 additions & 2 deletions examples/tutorial_builder/03_02_option.rs
@@ -1,7 +1,7 @@
use clap::{app_from_crate, arg};
use clap::{arg, command};

fn main() {
let matches = app_from_crate!()
let matches = command!()
.arg(arg!(-n --name <NAME>).required(false))
.get_matches();

Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/03_03_positional.rs
@@ -1,7 +1,7 @@
use clap::{app_from_crate, arg};
use clap::{arg, command};

fn main() {
let matches = app_from_crate!().arg(arg!([NAME])).get_matches();
let matches = command!().arg(arg!([NAME])).get_matches();

println!("NAME: {:?}", matches.value_of("NAME"));
}
4 changes: 2 additions & 2 deletions examples/tutorial_builder/03_04_subcommands.rs
@@ -1,7 +1,7 @@
use clap::{app_from_crate, arg, Command};
use clap::{arg, command, Command};

fn main() {
let matches = app_from_crate!()
let matches = command!()
.propagate_version(true)
.subcommand_required(true)
.arg_required_else_help(true)
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/03_05_default_values.rs
@@ -1,7 +1,7 @@
use clap::{app_from_crate, arg};
use clap::{arg, command};

fn main() {
let matches = app_from_crate!()
let matches = command!()
.arg(arg!([NAME]).default_value("alice"))
.get_matches();

Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/04_01_enum.rs
@@ -1,4 +1,4 @@
use clap::{app_from_crate, arg, ArgEnum, PossibleValue};
use clap::{arg, command, ArgEnum, PossibleValue};

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ArgEnum)]
enum Mode {
Expand Down Expand Up @@ -37,7 +37,7 @@ impl std::str::FromStr for Mode {
}

fn main() {
let matches = app_from_crate!()
let matches = command!()
.arg(
arg!(<MODE>)
.help("What mode to run the program in")
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/04_01_possible.rs
@@ -1,7 +1,7 @@
use clap::{app_from_crate, arg};
use clap::{arg, command};

fn main() {
let matches = app_from_crate!()
let matches = command!()
.arg(
arg!(<MODE>)
.help("What mode to run the program in")
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/04_02_parse.rs
@@ -1,7 +1,7 @@
use clap::{app_from_crate, arg};
use clap::{arg, command};

fn main() {
let matches = app_from_crate!()
let matches = command!()
.arg(
arg!(<PORT>)
.help("Network port to use")
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/04_02_validate.rs
@@ -1,11 +1,11 @@
use clap::{app_from_crate, arg};
use clap::{arg, command};
use std::ops::RangeInclusive;
use std::str::FromStr;

const PORT_RANGE: RangeInclusive<usize> = 1..=65535;

fn main() {
let matches = app_from_crate!()
let matches = command!()
.arg(arg!(<PORT>).help("Network port to use").validator(|s| {
usize::from_str(s)
.map(|port| PORT_RANGE.contains(&port))
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/04_03_relations.rs
@@ -1,8 +1,8 @@
use clap::{app_from_crate, arg, ArgGroup};
use clap::{arg, command, ArgGroup};

fn main() {
// Create application like normal
let matches = app_from_crate!()
let matches = command!()
// Add the version arguments
.arg(arg!(--"set-ver" <VER> "set version manually").required(false))
.arg(arg!(--major "auto inc major"))
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/04_04_custom.rs
@@ -1,8 +1,8 @@
use clap::{app_from_crate, arg, ErrorKind};
use clap::{arg, command, ErrorKind};

fn main() {
// Create application like normal
let mut cmd = app_from_crate!()
let mut cmd = command!()
// Add the version arguments
.arg(arg!(--"set-ver" <VER> "set version manually").required(false))
.arg(arg!(--major "auto inc major"))
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/05_01_assert.rs
@@ -1,4 +1,4 @@
use clap::{app_from_crate, arg};
use clap::{arg, command};

fn main() {
let matches = cmd().get_matches();
Expand All @@ -11,7 +11,7 @@ fn main() {
}

fn cmd() -> clap::Command<'static> {
app_from_crate!().arg(
command!().arg(
arg!(<PORT>)
.help("Network port to use")
.validator(|s| s.parse::<usize>()),
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial_builder/README.md
Expand Up @@ -86,7 +86,7 @@ MyApp 1.0

```

You can use `app_from_crate!()` to fill these fields in from your `Cargo.toml`
You can use `command!()` to fill these fields in from your `Cargo.toml`
file. **This requires the `cargo` feature flag.**

[Example:](02_crate.rs)
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial_derive/README.md
Expand Up @@ -89,7 +89,7 @@ MyApp 1.0

```

You can use `app_from_crate!()` to fill these fields in from your `Cargo.toml` file.
You can use `command!()` to fill these fields in from your `Cargo.toml` file.

[Example:](02_crate.rs)
```console
Expand Down
2 changes: 1 addition & 1 deletion src/build/command.rs
Expand Up @@ -111,7 +111,7 @@ impl<'help> App<'help> {
/// name will only be displayed to the user when they request to print
/// version or help and usage information.
///
/// See also [`app_from_crate!`](crate::app_from_crate!) and [`crate_name!`](crate::crate_name!).
/// See also [`command!`](crate::command!) and [`crate_name!`](crate::crate_name!).
///
/// # Examples
///
Expand Down
1 change: 1 addition & 0 deletions src/macros.rs
Expand Up @@ -324,6 +324,7 @@ macro_rules! command {

/// Deprecated, replaced with [`clap::command!`]
#[cfg(feature = "cargo")]
#[deprecated(since = "3.1.0", note = "Replaced with `clap::command!")]
#[macro_export]
macro_rules! app_from_crate {
() => {{
Expand Down
1 change: 1 addition & 0 deletions tests/builder/app_from_crate.rs
@@ -1,4 +1,5 @@
#![cfg(feature = "cargo")]
#![allow(deprecated)]

use clap::{app_from_crate, error::ErrorKind};

Expand Down

0 comments on commit 4eb269e

Please sign in to comment.