aboutsummaryrefslogtreecommitdiff
path: root/clap/benches/04_new_help.rs
blob: f033efb5a19d93300fe82516c00a9ffa9c2e965f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#![feature(test)]

extern crate clap;
extern crate test;

use test::Bencher;

use std::io::Cursor;

use clap::App;
use clap::{Arg, SubCommand};

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

fn app_example1<'b, 'c>() -> App<'b, 'c> {
    App::new("MyApp")
        .version("1.0")
        .author("Kevin K. <kbknapp@gmail.com>")
        .about("Does awesome things")
        .args_from_usage("-c, --config=[FILE] 'Sets a custom config file'
                          <output> 'Sets an optional output file'
                          -d... 'Turn debugging information on'")
        .subcommand(SubCommand::with_name("test")
            .about("does testing things")
            .arg_from_usage("-l, --list 'lists test values'"))
}

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

fn app_example3<'b, 'c>() -> App<'b, 'c> {
    App::new("MyApp")
        .arg(Arg::with_name("debug")
            .help("turn on debugging information")
            .short("d"))
        .args(&[Arg::with_name("config")
                    .help("sets the config file to use")
                    .takes_value(true)
                    .short("c")
                    .long("config"),
                Arg::with_name("input")
                    .help("the input file to use")
                    .index(1)
                    .required(true)])
        .arg_from_usage("--license 'display the license file'")
        .args_from_usage("[output] 'Supply an output file to use'
                          -i, --int=[IFACE] 'Set an interface to use'")
}

fn app_example4<'b, 'c>() -> App<'b, 'c> {
    App::new("MyApp")
        .about("Parses an input file to do awesome things")
        .version("1.0")
        .author("Kevin K. <kbknapp@gmail.com>")
        .arg(Arg::with_name("debug")
            .help("turn on debugging information")
            .short("d")
            .long("debug"))
        .arg(Arg::with_name("config")
            .help("sets the config file to use")
            .short("c")
            .long("config"))
        .arg(Arg::with_name("input")
            .help("the input file to use")
            .index(1)
            .required(true))
}

fn app_example5<'b, 'c>() -> App<'b, 'c> {
    App::new("MyApp").arg(Arg::with_name("awesome")
        .help("turns up the awesome")
        .short("a")
        .long("awesome")
        .multiple(true)
        .requires("config")
        .conflicts_with("output"))
}

fn app_example6<'b, 'c>() -> App<'b, 'c> {
    App::new("MyApp")
        .arg(Arg::with_name("input")
            .help("the input file to use")
            .index(1)
            .requires("config")
            .conflicts_with("output")
            .required(true))
        .arg(Arg::with_name("config")
            .help("the config file to use")
            .index(2))
}

fn app_example7<'b, 'c>() -> App<'b, 'c> {
    App::new("MyApp")
        .arg(Arg::with_name("config"))
        .arg(Arg::with_name("output"))
        .arg(Arg::with_name("input")
            .help("the input file to use")
            .takes_value(true)
            .short("i")
            .long("input")
            .multiple(true)
            .required(true)
            .requires("config")
            .conflicts_with("output"))
}

fn app_example8<'b, 'c>() -> App<'b, 'c> {
    App::new("MyApp")
        .arg(Arg::with_name("config"))
        .arg(Arg::with_name("output"))
        .arg(Arg::with_name("input")
            .help("the input file to use")
            .takes_value(true)
            .short("i")
            .long("input")
            .multiple(true)
            .required(true)
            .requires("config")
            .conflicts_with("output"))
}

fn app_example10<'b, 'c>() -> App<'b, 'c> {
    App::new("myapp")
        .about("does awesome things")
        .arg(Arg::with_name("CONFIG")
            .help("The config file to use (default is \"config.json\")")
            .short("c")
            .takes_value(true))
}

#[bench]
fn example1(b: &mut Bencher) {
    let app = app_example1();
    b.iter(|| build_help(&app));
}

#[bench]
fn example2(b: &mut Bencher) {
    let app = app_example2();
    b.iter(|| build_help(&app));
}

#[bench]
fn example3(b: &mut Bencher) {
    let app = app_example3();
    b.iter(|| build_help(&app));
}

#[bench]
fn example4(b: &mut Bencher) {
    let app = app_example4();
    b.iter(|| build_help(&app));
}

#[bench]
fn example5(b: &mut Bencher) {
    let app = app_example5();
    b.iter(|| build_help(&app));
}

#[bench]
fn example6(b: &mut Bencher) {
    let app = app_example6();
    b.iter(|| build_help(&app));
}

#[bench]
fn example7(b: &mut Bencher) {
    let app = app_example7();
    b.iter(|| build_help(&app));
}

#[bench]
fn example8(b: &mut Bencher) {
    let app = app_example8();
    b.iter(|| build_help(&app));
}

#[bench]
fn example10(b: &mut Bencher) {
    let app = app_example10();
    b.iter(|| build_help(&app));
}

#[bench]
fn example4_template(b: &mut Bencher) {
    let app = app_example4().template("{bin} {version}\n{author}\n{about}\n\nUSAGE:\n    {usage}\n\nFLAGS:\n{flags}\n\nARGS:\n{args}\n");
    b.iter(|| build_help(&app));
}