2015-10-01 03:34:23 +00:00
|
|
|
extern crate clap;
|
2017-01-03 04:05:23 +00:00
|
|
|
extern crate regex;
|
2015-10-01 03:34:23 +00:00
|
|
|
|
|
|
|
use clap::{App, Arg};
|
|
|
|
|
2017-01-03 04:05:23 +00:00
|
|
|
include!("../clap-test.rs");
|
2015-10-01 03:34:23 +00:00
|
|
|
|
2017-03-03 08:32:09 +00:00
|
|
|
static HIDDEN_ARGS: &'static str = "test 1.4
|
2015-10-01 03:34:23 +00:00
|
|
|
Kevin K.
|
|
|
|
tests stuff
|
|
|
|
|
|
|
|
USAGE:
|
2017-03-09 22:53:36 +00:00
|
|
|
test [FLAGS] [OPTIONS]
|
2015-10-01 03:34:23 +00:00
|
|
|
|
|
|
|
FLAGS:
|
|
|
|
-F, --flag2 some other flag
|
|
|
|
-h, --help Prints help information
|
|
|
|
-V, --version Prints version information
|
|
|
|
|
|
|
|
OPTIONS:
|
2017-01-03 04:05:23 +00:00
|
|
|
--option <opt> some option";
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hidden_args() {
|
|
|
|
let app = App::new("test")
|
|
|
|
.author("Kevin K.")
|
|
|
|
.about("tests stuff")
|
2017-03-03 08:32:09 +00:00
|
|
|
.version("1.4")
|
2018-01-25 04:05:05 +00:00
|
|
|
.args(&[
|
2018-04-21 18:59:19 +00:00
|
|
|
Arg::from("-f, --flag 'some flag'").hidden(true),
|
|
|
|
Arg::from("-F, --flag2 'some other flag'"),
|
|
|
|
Arg::from("--option [opt] 'some option'"),
|
2018-04-04 03:01:45 +00:00
|
|
|
Arg::with_name("DUMMY").hidden(true),
|
2018-01-25 04:05:05 +00:00
|
|
|
]);
|
2017-01-03 04:05:23 +00:00
|
|
|
assert!(test::compare_output(app, "test --help", HIDDEN_ARGS, false));
|
2015-10-01 03:34:23 +00:00
|
|
|
}
|
2018-04-04 00:00:21 +00:00
|
|
|
|
|
|
|
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")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('c')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("config")
|
|
|
|
.hidden_short_help(true)
|
2018-08-02 03:13:51 +00:00
|
|
|
.help("Some help text describing the --config arg"),
|
2018-04-04 00:00:21 +00:00
|
|
|
Arg::with_name("visible")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('v')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("visible")
|
2018-08-02 03:13:51 +00:00
|
|
|
.help("This text should be visible"),
|
|
|
|
]);
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2018-08-02 03:13:51 +00:00
|
|
|
assert!(test::compare_output(
|
|
|
|
app,
|
|
|
|
"test -h",
|
|
|
|
HIDDEN_SHORT_ARGS,
|
|
|
|
false
|
|
|
|
));
|
2018-04-04 00:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// 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")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('c')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("config")
|
|
|
|
.hidden_short_help(true)
|
2018-08-02 03:13:51 +00:00
|
|
|
.help("Some help text describing the --config arg"),
|
2018-04-04 00:00:21 +00:00
|
|
|
Arg::with_name("visible")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('v')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("visible")
|
2018-08-02 03:13:51 +00:00
|
|
|
.help("This text should be visible"),
|
|
|
|
]);
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2018-08-02 03:13:51 +00:00
|
|
|
assert!(test::compare_output(
|
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
HIDDEN_SHORT_ARGS_LONG_HELP,
|
|
|
|
false
|
|
|
|
));
|
2018-04-04 00:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('c')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("config")
|
|
|
|
.hidden_long_help(true)
|
2018-08-02 03:13:51 +00:00
|
|
|
.help("Some help text describing the --config arg"),
|
2018-04-04 00:00:21 +00:00
|
|
|
Arg::with_name("visible")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('v')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("visible")
|
2018-08-02 03:13:51 +00:00
|
|
|
.help("This text should be visible"),
|
|
|
|
]);
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2018-08-02 03:13:51 +00:00
|
|
|
assert!(test::compare_output(
|
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
HIDDEN_LONG_ARGS,
|
|
|
|
false
|
|
|
|
));
|
2018-04-04 00:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('c')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("config")
|
|
|
|
.hidden_long_help(true)
|
2018-08-02 03:13:51 +00:00
|
|
|
.help("Some help text describing the --config arg"),
|
2018-04-04 00:00:21 +00:00
|
|
|
Arg::with_name("visible")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('v')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("visible")
|
2018-08-02 03:13:51 +00:00
|
|
|
.help("This text should be visible"),
|
|
|
|
]);
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2018-08-02 03:13:51 +00:00
|
|
|
assert!(test::compare_output(
|
|
|
|
app,
|
|
|
|
"test -h",
|
|
|
|
HIDDEN_LONG_ARGS_SHORT_HELP,
|
|
|
|
false
|
|
|
|
));
|
|
|
|
}
|