Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Rename App to Command #3472

Merged
merged 7 commits into from Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -119,7 +119,7 @@ Why use the procedural [Builder API](https://github.com/clap-rs/clap/blob/v3.0.1

- [wild](https://crates.io/crates/wild) for supporting wildcards (`*`) on Windows like you do Linux
- [argfile](https://crates.io/crates/argfile) for loading additional arguments from a file (aka response files)
- [shadow-rs](https://crates.io/crates/shadow-rs) for generating `App::long_version`
- [shadow-rs](https://crates.io/crates/shadow-rs) for generating `Command::long_version`
- [clap_mangen](https://crates.io/crates/clap_mangen) for generating man page source (roff)
- [clap_complete](https://crates.io/crates/clap_complete) for shell completion support
- [clap-verbosity-flag](https://crates.io/crates/clap-verbosity-flag)
Expand Down Expand Up @@ -150,8 +150,8 @@ Why use the procedural [Builder API](https://github.com/clap-rs/clap/blob/v3.0.1

**Warning:** These may contain breaking changes between minor releases.

* **unstable-replace**: Enable [`App::replace`](https://github.com/clap-rs/clap/issues/2836)
* **unstable-multicall**: Enable [`App::multicall`](https://github.com/clap-rs/clap/issues/2861)
* **unstable-replace**: Enable [`Command::replace`](https://github.com/clap-rs/clap/issues/2836)
* **unstable-multicall**: Enable [`Command::multicall`](https://github.com/clap-rs/clap/issues/2861)
* **unstable-grouped**: Enable [`ArgMatches::grouped_values_of`](https://github.com/clap-rs/clap/issues/2924)

## Sponsors
Expand Down
6 changes: 3 additions & 3 deletions benches/01_default.rs
@@ -1,13 +1,13 @@
use clap::App;
use clap::Command;
use criterion::{criterion_group, criterion_main, Criterion};

pub fn build_empty(c: &mut Criterion) {
c.bench_function("build_empty", |b| b.iter(|| App::new("claptests")));
c.bench_function("build_empty", |b| b.iter(|| Command::new("claptests")));
}

pub fn parse_empty(c: &mut Criterion) {
c.bench_function("parse_empty", |b| {
b.iter(|| App::new("claptests").get_matches_from(vec![""]))
b.iter(|| Command::new("claptests").get_matches_from(vec![""]))
});
}

Expand Down
16 changes: 8 additions & 8 deletions benches/02_simple.rs
@@ -1,9 +1,9 @@
use clap::{arg, App, Arg};
use clap::{arg, Arg, Command};
use criterion::{criterion_group, criterion_main, Criterion};

macro_rules! create_app {
() => {{
App::new("claptests")
Command::new("claptests")
.version("0.1")
.about("tests clap library")
.author("Kevin K. <kbknapp@gmail.com>")
Expand All @@ -19,45 +19,45 @@ pub fn build_simple(c: &mut Criterion) {

pub fn build_with_flag(c: &mut Criterion) {
c.bench_function("build_with_flag", |b| {
b.iter(|| App::new("claptests").arg(arg!(-s --some "something")))
b.iter(|| Command::new("claptests").arg(arg!(-s --some "something")))
});
}

pub fn build_with_flag_ref(c: &mut Criterion) {
c.bench_function("build_with_flag_ref", |b| {
b.iter(|| {
let arg = arg!(-s --some "something");
App::new("claptests").arg(&arg)
Command::new("claptests").arg(&arg)
})
});
}

pub fn build_with_opt(c: &mut Criterion) {
c.bench_function("build_with_opt", |b| {
b.iter(|| App::new("claptests").arg(arg!(-s --some <FILE> "something")))
b.iter(|| Command::new("claptests").arg(arg!(-s --some <FILE> "something")))
});
}

pub fn build_with_opt_ref(c: &mut Criterion) {
c.bench_function("build_with_opt_ref", |b| {
b.iter(|| {
let arg = arg!(-s --some <FILE> "something");
App::new("claptests").arg(&arg)
Command::new("claptests").arg(&arg)
})
});
}

pub fn build_with_pos(c: &mut Criterion) {
c.bench_function("build_with_pos", |b| {
b.iter(|| App::new("claptests").arg(Arg::new("some")))
b.iter(|| Command::new("claptests").arg(Arg::new("some")))
});
}

pub fn build_with_pos_ref(c: &mut Criterion) {
c.bench_function("build_with_pos_ref", |b| {
b.iter(|| {
let arg = Arg::new("some");
App::new("claptests").arg(&arg)
Command::new("claptests").arg(&arg)
})
});
}
Expand Down
10 changes: 5 additions & 5 deletions benches/03_complex.rs
@@ -1,12 +1,12 @@
use clap::{arg, App, Arg};
use clap::{arg, Arg, Command};
use criterion::{criterion_group, criterion_main, Criterion};

static OPT3_VALS: [&str; 2] = ["fast", "slow"];
static POS3_VALS: [&str; 2] = ["vi", "emacs"];

macro_rules! create_app {
() => {{
App::new("claptests")
Command::new("claptests")
.version("0.1")
.about("tests clap library")
.author("Kevin K. <kbknapp@gmail.com>")
Expand Down Expand Up @@ -35,7 +35,7 @@ macro_rules! create_app {
arg!(--maxvals3 <maxvals> ... "Tests 3 max vals").max_values(3).multiple_values(true).required(false),
])
.subcommand(
App::new("subcmd")
Command::new("subcmd")
.about("tests subcommands")
.version("0.1")
.author("Kevin K. <kbknapp@gmail.com>")
Expand All @@ -48,7 +48,7 @@ macro_rules! create_app {
pub fn build_from_builder(c: &mut Criterion) {
c.bench_function("build_from_builder", |b| {
b.iter(|| {
App::new("claptests")
Command::new("claptests")
.version("0.1")
.about("tests clap library")
.author("Kevin K. <kbknapp@gmail.com>")
Expand Down Expand Up @@ -141,7 +141,7 @@ pub fn build_from_builder(c: &mut Criterion) {
.max_values(3),
)
.subcommand(
App::new("subcmd")
Command::new("subcmd")
.about("tests subcommands")
.version("0.1")
.author("Kevin K. <kbknapp@gmail.com>")
Expand Down
84 changes: 42 additions & 42 deletions benches/04_new_help.rs
@@ -1,17 +1,17 @@
use clap::App;
use clap::Command;
use clap::{arg, Arg};
use criterion::{criterion_group, criterion_main, Criterion};
use std::io::Cursor;

fn build_help(app: &mut App) -> String {
fn build_help(cmd: &mut Command) -> String {
let mut buf = Cursor::new(Vec::with_capacity(50));
app.write_help(&mut buf).unwrap();
cmd.write_help(&mut buf).unwrap();
let content = buf.into_inner();
String::from_utf8(content).unwrap()
}

fn app_example1<'c>() -> App<'c> {
App::new("MyApp")
fn app_example1<'c>() -> Command<'c> {
Command::new("MyApp")
.version("1.0")
.author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things")
Expand All @@ -24,21 +24,21 @@ fn app_example1<'c>() -> App<'c> {
.arg(arg!(<output> "Sets an optional output file"))
.arg(arg!(d: -d ... "Turn debugging information on"))
.subcommand(
App::new("test")
Command::new("test")
.about("does testing things")
.arg(arg!(-l --list "lists test values")),
)
}

fn app_example2<'c>() -> App<'c> {
App::new("MyApp")
fn app_example2<'c>() -> Command<'c> {
Command::new("MyApp")
.version("1.0")
.author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things")
}

fn app_example3<'c>() -> App<'c> {
App::new("MyApp")
fn app_example3<'c>() -> Command<'c> {
Command::new("MyApp")
.arg(
Arg::new("debug")
.help("turn on debugging information")
Expand All @@ -64,8 +64,8 @@ fn app_example3<'c>() -> App<'c> {
)
}

fn app_example4<'c>() -> App<'c> {
App::new("MyApp")
fn app_example4<'c>() -> Command<'c> {
Command::new("MyApp")
.about("Parses an input file to do awesome things")
.version("1.0")
.author("Kevin K. <kbknapp@gmail.com>")
Expand All @@ -89,8 +89,8 @@ fn app_example4<'c>() -> App<'c> {
)
}

fn app_example5<'c>() -> App<'c> {
App::new("MyApp").arg(
fn app_example5<'c>() -> Command<'c> {
Command::new("MyApp").arg(
Arg::new("awesome")
.help("turns up the awesome")
.short('a')
Expand All @@ -99,8 +99,8 @@ fn app_example5<'c>() -> App<'c> {
)
}

fn app_example6<'c>() -> App<'c> {
App::new("MyApp")
fn app_example6<'c>() -> Command<'c> {
Command::new("MyApp")
.arg(
Arg::new("input")
.help("the input file to use")
Expand All @@ -111,8 +111,8 @@ fn app_example6<'c>() -> App<'c> {
.arg(Arg::new("config").help("the config file to use").index(2))
}

fn app_example7<'c>() -> App<'c> {
App::new("MyApp")
fn app_example7<'c>() -> Command<'c> {
Command::new("MyApp")
.arg(Arg::new("config"))
.arg(Arg::new("output"))
.arg(
Expand All @@ -129,8 +129,8 @@ fn app_example7<'c>() -> App<'c> {
)
}

fn app_example8<'c>() -> App<'c> {
App::new("MyApp")
fn app_example8<'c>() -> Command<'c> {
Command::new("MyApp")
.arg(Arg::new("config"))
.arg(Arg::new("output"))
.arg(
Expand All @@ -147,8 +147,8 @@ fn app_example8<'c>() -> App<'c> {
)
}

fn app_example10<'c>() -> App<'c> {
App::new("myapp").about("does awesome things").arg(
fn app_example10<'c>() -> Command<'c> {
Command::new("myapp").about("does awesome things").arg(
Arg::new("CONFIG")
.help("The config file to use (default is \"config.json\")")
.short('c')
Expand All @@ -157,53 +157,53 @@ fn app_example10<'c>() -> App<'c> {
}

pub fn example1(c: &mut Criterion) {
let mut app = app_example1();
c.bench_function("example1", |b| b.iter(|| build_help(&mut app)));
let mut cmd = app_example1();
c.bench_function("example1", |b| b.iter(|| build_help(&mut cmd)));
}

pub fn example2(c: &mut Criterion) {
let mut app = app_example2();
c.bench_function("example2", |b| b.iter(|| build_help(&mut app)));
let mut cmd = app_example2();
c.bench_function("example2", |b| b.iter(|| build_help(&mut cmd)));
}

pub fn example3(c: &mut Criterion) {
let mut app = app_example3();
c.bench_function("example3", |b| b.iter(|| build_help(&mut app)));
let mut cmd = app_example3();
c.bench_function("example3", |b| b.iter(|| build_help(&mut cmd)));
}

pub fn example4(c: &mut Criterion) {
let mut app = app_example4();
c.bench_function("example4", |b| b.iter(|| build_help(&mut app)));
let mut cmd = app_example4();
c.bench_function("example4", |b| b.iter(|| build_help(&mut cmd)));
}

pub fn example5(c: &mut Criterion) {
let mut app = app_example5();
c.bench_function("example5", |b| b.iter(|| build_help(&mut app)));
let mut cmd = app_example5();
c.bench_function("example5", |b| b.iter(|| build_help(&mut cmd)));
}

pub fn example6(c: &mut Criterion) {
let mut app = app_example6();
c.bench_function("example6", |b| b.iter(|| build_help(&mut app)));
let mut cmd = app_example6();
c.bench_function("example6", |b| b.iter(|| build_help(&mut cmd)));
}

pub fn example7(c: &mut Criterion) {
let mut app = app_example7();
c.bench_function("example7", |b| b.iter(|| build_help(&mut app)));
let mut cmd = app_example7();
c.bench_function("example7", |b| b.iter(|| build_help(&mut cmd)));
}

pub fn example8(c: &mut Criterion) {
let mut app = app_example8();
c.bench_function("example8", |b| b.iter(|| build_help(&mut app)));
let mut cmd = app_example8();
c.bench_function("example8", |b| b.iter(|| build_help(&mut cmd)));
}

pub fn example10(c: &mut Criterion) {
let mut app = app_example10();
c.bench_function("example10", |b| b.iter(|| build_help(&mut app)));
let mut cmd = app_example10();
c.bench_function("example10", |b| b.iter(|| build_help(&mut cmd)));
}

pub fn example4_template(c: &mut Criterion) {
let mut app = app_example4().help_template("{bin} {version}\n{author}\n{about}\n\nUSAGE:\n {usage}\n\nOPTIONS:\n{options}\n\nARGS:\n{args}\n");
c.bench_function("example4_template", |b| b.iter(|| build_help(&mut app)));
let mut cmd = app_example4().help_template("{bin} {version}\n{author}\n{about}\n\nUSAGE:\n {usage}\n\nOPTIONS:\n{options}\n\nARGS:\n{args}\n");
c.bench_function("example4_template", |b| b.iter(|| build_help(&mut cmd)));
}

criterion_group!(
Expand Down