aboutsummaryrefslogtreecommitdiff
path: root/clap/tests/hidden_args.rs
blob: 635e25e2ae52a0058298d98fd1bc4efa90551ccd (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
extern crate clap;
extern crate regex;

use clap::{App, Arg};

include!("../clap-test.rs");

static HIDDEN_ARGS: &'static str = "test 1.4
Kevin K.
tests stuff

USAGE:
    test [FLAGS] [OPTIONS]

FLAGS:
    -F, --flag2      some other flag
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
        --option <opt>    some option";

#[test]
fn hidden_args() {
    let app = App::new("test")
        .author("Kevin K.")
        .about("tests stuff")
        .version("1.4")
        .args(&[Arg::from_usage("-f, --flag 'some flag'").hidden(true),
                    Arg::from_usage("-F, --flag2 'some other flag'"),
                    Arg::from_usage("--option [opt] 'some option'"),
                    Arg::with_name("DUMMY").required(false).hidden(true)]);
    assert!(test::compare_output(app, "test --help", HIDDEN_ARGS, false));
}

static HIDDEN_SHORT_ARGS: &'static str = "test 2.31.2
Steve P.
hides short args

USAGE:
    test [FLAGS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information
    -v, --visible    This text should be visible";

static HIDDEN_SHORT_ARGS_LONG_HELP: &'static str = "test 2.31.2
Steve P.
hides short args

USAGE:
    test [FLAGS]

FLAGS:
    -c, --config     
            Some help text describing the --config arg

    -h, --help       
            Prints help information

    -V, --version    
            Prints version information

    -v, --visible    
            This text should be visible";

/// Ensure hidden with short option
#[test]
fn hidden_short_args() {
    let app = App::new("test")
        .about("hides short args")
        .author("Steve P.")
        .version("2.31.2")
        .args(&[
            Arg::with_name("cfg")
                .short("c")
                .long("config")
                .hidden_short_help(true)
                .help("Some help text describing the --config arg"),                
            Arg::with_name("visible")
                .short("v")
                .long("visible")
                .help("This text should be visible")]);

    assert!(test::compare_output(app, "test -h", HIDDEN_SHORT_ARGS, false));        
}

/// Ensure visible with opposite option
#[test]
fn hidden_short_args_long_help() {
    let app = App::new("test")
        .about("hides short args")
        .author("Steve P.")
        .version("2.31.2")
        .args(&[
            Arg::with_name("cfg")
                .short("c")
                .long("config")
                .hidden_short_help(true)
                .help("Some help text describing the --config arg"),                
            Arg::with_name("visible")
                .short("v")
                .long("visible")
                .help("This text should be visible")]);

    assert!(test::compare_output(app, "test --help", HIDDEN_SHORT_ARGS_LONG_HELP, false));        
}

static HIDDEN_LONG_ARGS: &'static str = "test 2.31.2
Steve P.
hides long args

USAGE:
    test [FLAGS]

FLAGS:
    -h, --help       
            Prints help information

    -V, --version    
            Prints version information

    -v, --visible    
            This text should be visible";

#[test]
fn hidden_long_args() {
    let app = App::new("test")
        .about("hides long args")
        .author("Steve P.")
        .version("2.31.2")
        .args(&[
            Arg::with_name("cfg")
                .short("c")
                .long("config")
                .hidden_long_help(true)
                .help("Some help text describing the --config arg"),                
            Arg::with_name("visible")
                .short("v")
                .long("visible")
                .help("This text should be visible")]);

    assert!(test::compare_output(app, "test --help", HIDDEN_LONG_ARGS, false));        
}

static HIDDEN_LONG_ARGS_SHORT_HELP: &'static str = "test 2.31.2
Steve P.
hides long args

USAGE:
    test [FLAGS]

FLAGS:
    -c, --config     Some help text describing the --config arg
    -h, --help       Prints help information
    -V, --version    Prints version information
    -v, --visible    This text should be visible";

#[test]
fn hidden_long_args_short_help() {
    let app = App::new("test")
        .about("hides long args")
        .author("Steve P.")
        .version("2.31.2")
        .args(&[
            Arg::with_name("cfg")
                .short("c")
                .long("config")
                .hidden_long_help(true)
                .help("Some help text describing the --config arg"),                
            Arg::with_name("visible")
                .short("v")
                .long("visible")
                .help("This text should be visible")]);

    assert!(test::compare_output(app, "test -h", HIDDEN_LONG_ARGS_SHORT_HELP, false));        
}