2020-02-04 09:10:53 +01:00
|
|
|
mod utils;
|
2015-09-30 23:34:23 -04:00
|
|
|
|
2021-02-08 03:33:57 +00:00
|
|
|
use clap::{App, AppSettings, Arg};
|
2015-09-30 23:34:23 -04:00
|
|
|
|
2019-10-02 16:27:19 +03:00
|
|
|
static HIDDEN_ARGS: &str = "test 1.4
|
2021-02-27 16:20:52 +01:00
|
|
|
|
2015-09-30 23:34:23 -04:00
|
|
|
Kevin K.
|
2021-02-27 16:20:52 +01:00
|
|
|
|
2015-09-30 23:34:23 -04:00
|
|
|
tests stuff
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 17:01:33 -05:00
|
|
|
test [OPTIONS]
|
2015-09-30 23:34:23 -04:00
|
|
|
|
|
|
|
OPTIONS:
|
2021-10-11 17:01:33 -05:00
|
|
|
-F, --flag2 some other flag
|
|
|
|
-h, --help Print help information
|
2021-09-24 11:58:39 -04:00
|
|
|
--option <opt> some option
|
2021-10-11 17:01:33 -05:00
|
|
|
-V, --version Print version information
|
2021-09-24 11:58:39 -04:00
|
|
|
";
|
2017-01-02 23:05:23 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hidden_args() {
|
|
|
|
let app = App::new("test")
|
|
|
|
.author("Kevin K.")
|
|
|
|
.about("tests stuff")
|
2017-03-03 09:32:09 +01:00
|
|
|
.version("1.4")
|
2018-01-24 23:05:05 -05:00
|
|
|
.args(&[
|
2018-04-21 11:59:19 -07:00
|
|
|
Arg::from("-f, --flag 'some flag'").hidden(true),
|
|
|
|
Arg::from("-F, --flag2 'some other flag'"),
|
|
|
|
Arg::from("--option [opt] 'some option'"),
|
2020-05-14 22:50:56 +02:00
|
|
|
Arg::new("DUMMY").hidden(true),
|
2018-01-24 23:05:05 -05:00
|
|
|
]);
|
2020-02-04 09:10:53 +01:00
|
|
|
assert!(utils::compare_output(
|
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
HIDDEN_ARGS,
|
|
|
|
false
|
|
|
|
));
|
2015-09-30 23:34:23 -04:00
|
|
|
}
|
2018-04-03 20:00:21 -04:00
|
|
|
|
2019-10-02 16:27:19 +03:00
|
|
|
static HIDDEN_SHORT_ARGS: &str = "test 2.31.2
|
2021-02-27 16:20:52 +01:00
|
|
|
|
2018-04-03 20:00:21 -04:00
|
|
|
Steve P.
|
2021-02-27 16:20:52 +01:00
|
|
|
|
2018-04-03 20:00:21 -04:00
|
|
|
hides short args
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 17:01:33 -05:00
|
|
|
test [OPTIONS]
|
2018-04-03 20:00:21 -04:00
|
|
|
|
2021-10-11 17:01:33 -05:00
|
|
|
OPTIONS:
|
2021-07-29 20:23:25 -07:00
|
|
|
-h, --help Print help information
|
2020-10-10 23:11:42 +08:00
|
|
|
-v, --visible This text should be visible
|
2021-09-24 11:58:39 -04:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2018-04-03 20:00:21 -04:00
|
|
|
|
2019-10-02 16:27:19 +03:00
|
|
|
static HIDDEN_SHORT_ARGS_LONG_HELP: &str = "test 2.31.2
|
2021-02-27 16:20:52 +01:00
|
|
|
|
2018-04-03 20:00:21 -04:00
|
|
|
Steve P.
|
2021-02-27 16:20:52 +01:00
|
|
|
|
2018-04-03 20:00:21 -04:00
|
|
|
hides short args
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 17:01:33 -05:00
|
|
|
test [OPTIONS]
|
2018-04-03 20:00:21 -04:00
|
|
|
|
2021-10-11 17:01:33 -05:00
|
|
|
OPTIONS:
|
2020-08-20 15:45:38 +03:00
|
|
|
-c, --config
|
2018-04-03 20:00:21 -04:00
|
|
|
Some help text describing the --config arg
|
|
|
|
|
2020-08-20 15:45:38 +03:00
|
|
|
-h, --help
|
2021-07-29 20:23:25 -07:00
|
|
|
Print help information
|
2018-04-03 20:00:21 -04:00
|
|
|
|
2020-08-20 15:45:38 +03:00
|
|
|
-v, --visible
|
2020-10-10 23:11:42 +08:00
|
|
|
This text should be visible
|
|
|
|
|
|
|
|
-V, --version
|
2021-09-24 11:58:39 -04:00
|
|
|
Print version information
|
|
|
|
";
|
2018-04-03 20:00:21 -04:00
|
|
|
|
|
|
|
/// 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(&[
|
2020-05-14 22:50:56 +02:00
|
|
|
Arg::new("cfg")
|
2018-07-23 15:09:42 -04:00
|
|
|
.short('c')
|
2018-04-03 20:00:21 -04:00
|
|
|
.long("config")
|
|
|
|
.hidden_short_help(true)
|
2020-04-21 21:21:38 +05:30
|
|
|
.about("Some help text describing the --config arg"),
|
2020-05-14 22:50:56 +02:00
|
|
|
Arg::new("visible")
|
2018-07-23 15:09:42 -04:00
|
|
|
.short('v')
|
2018-04-03 20:00:21 -04:00
|
|
|
.long("visible")
|
2020-04-21 21:21:38 +05:30
|
|
|
.about("This text should be visible"),
|
2018-08-01 23:13:51 -04:00
|
|
|
]);
|
2018-04-03 20:00:21 -04:00
|
|
|
|
2020-02-04 09:10:53 +01:00
|
|
|
assert!(utils::compare_output(
|
2018-08-01 23:13:51 -04:00
|
|
|
app,
|
|
|
|
"test -h",
|
|
|
|
HIDDEN_SHORT_ARGS,
|
|
|
|
false
|
|
|
|
));
|
2018-04-03 20:00:21 -04: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(&[
|
2020-05-14 22:50:56 +02:00
|
|
|
Arg::new("cfg")
|
2018-07-23 15:09:42 -04:00
|
|
|
.short('c')
|
2018-04-03 20:00:21 -04:00
|
|
|
.long("config")
|
|
|
|
.hidden_short_help(true)
|
2020-04-21 21:21:38 +05:30
|
|
|
.about("Some help text describing the --config arg"),
|
2020-05-14 22:50:56 +02:00
|
|
|
Arg::new("visible")
|
2018-07-23 15:09:42 -04:00
|
|
|
.short('v')
|
2018-04-03 20:00:21 -04:00
|
|
|
.long("visible")
|
2020-04-21 21:21:38 +05:30
|
|
|
.about("This text should be visible"),
|
2018-08-01 23:13:51 -04:00
|
|
|
]);
|
2018-04-03 20:00:21 -04:00
|
|
|
|
2020-02-04 09:10:53 +01:00
|
|
|
assert!(utils::compare_output(
|
2018-08-01 23:13:51 -04:00
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
HIDDEN_SHORT_ARGS_LONG_HELP,
|
|
|
|
false
|
|
|
|
));
|
2018-04-03 20:00:21 -04:00
|
|
|
}
|
|
|
|
|
2019-10-02 16:27:19 +03:00
|
|
|
static HIDDEN_LONG_ARGS: &str = "test 2.31.2
|
2021-02-27 16:20:52 +01:00
|
|
|
|
2018-04-03 20:00:21 -04:00
|
|
|
Steve P.
|
2021-02-27 16:20:52 +01:00
|
|
|
|
2018-04-03 20:00:21 -04:00
|
|
|
hides long args
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 17:01:33 -05:00
|
|
|
test [OPTIONS]
|
2018-04-03 20:00:21 -04:00
|
|
|
|
2021-10-11 17:01:33 -05:00
|
|
|
OPTIONS:
|
2020-08-20 15:45:38 +03:00
|
|
|
-h, --help
|
2021-07-29 20:23:25 -07:00
|
|
|
Print help information
|
2018-04-03 20:00:21 -04:00
|
|
|
|
2020-08-20 15:45:38 +03:00
|
|
|
-v, --visible
|
2020-10-10 23:11:42 +08:00
|
|
|
This text should be visible
|
|
|
|
|
|
|
|
-V, --version
|
2021-09-24 11:58:39 -04:00
|
|
|
Print version information
|
|
|
|
";
|
2018-04-03 20:00:21 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hidden_long_args() {
|
|
|
|
let app = App::new("test")
|
|
|
|
.about("hides long args")
|
|
|
|
.author("Steve P.")
|
|
|
|
.version("2.31.2")
|
|
|
|
.args(&[
|
2020-05-14 22:50:56 +02:00
|
|
|
Arg::new("cfg")
|
2018-07-23 15:09:42 -04:00
|
|
|
.short('c')
|
2018-04-03 20:00:21 -04:00
|
|
|
.long("config")
|
|
|
|
.hidden_long_help(true)
|
2020-04-21 21:21:38 +05:30
|
|
|
.about("Some help text describing the --config arg"),
|
2020-05-14 22:50:56 +02:00
|
|
|
Arg::new("visible")
|
2018-07-23 15:09:42 -04:00
|
|
|
.short('v')
|
2018-04-03 20:00:21 -04:00
|
|
|
.long("visible")
|
2020-04-21 21:21:38 +05:30
|
|
|
.about("This text should be visible"),
|
2018-08-01 23:13:51 -04:00
|
|
|
]);
|
2018-04-03 20:00:21 -04:00
|
|
|
|
2020-02-04 09:10:53 +01:00
|
|
|
assert!(utils::compare_output(
|
2018-08-01 23:13:51 -04:00
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
HIDDEN_LONG_ARGS,
|
|
|
|
false
|
|
|
|
));
|
2018-04-03 20:00:21 -04:00
|
|
|
}
|
|
|
|
|
2019-10-02 16:27:19 +03:00
|
|
|
static HIDDEN_LONG_ARGS_SHORT_HELP: &str = "test 2.31.2
|
2021-02-27 16:20:52 +01:00
|
|
|
|
2018-04-03 20:00:21 -04:00
|
|
|
Steve P.
|
2021-02-27 16:20:52 +01:00
|
|
|
|
2018-04-03 20:00:21 -04:00
|
|
|
hides long args
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 17:01:33 -05:00
|
|
|
test [OPTIONS]
|
2018-04-03 20:00:21 -04:00
|
|
|
|
2021-10-11 17:01:33 -05:00
|
|
|
OPTIONS:
|
2018-04-03 20:00:21 -04:00
|
|
|
-c, --config Some help text describing the --config arg
|
2021-07-29 20:23:25 -07:00
|
|
|
-h, --help Print help information
|
2020-10-10 23:11:42 +08:00
|
|
|
-v, --visible This text should be visible
|
2021-09-24 11:58:39 -04:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2018-04-03 20:00:21 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hidden_long_args_short_help() {
|
|
|
|
let app = App::new("test")
|
|
|
|
.about("hides long args")
|
|
|
|
.author("Steve P.")
|
|
|
|
.version("2.31.2")
|
|
|
|
.args(&[
|
2020-05-14 22:50:56 +02:00
|
|
|
Arg::new("cfg")
|
2018-07-23 15:09:42 -04:00
|
|
|
.short('c')
|
2018-04-03 20:00:21 -04:00
|
|
|
.long("config")
|
|
|
|
.hidden_long_help(true)
|
2020-04-21 21:21:38 +05:30
|
|
|
.about("Some help text describing the --config arg"),
|
2020-05-14 22:50:56 +02:00
|
|
|
Arg::new("visible")
|
2018-07-23 15:09:42 -04:00
|
|
|
.short('v')
|
2018-04-03 20:00:21 -04:00
|
|
|
.long("visible")
|
2020-04-21 21:21:38 +05:30
|
|
|
.about("This text should be visible"),
|
2018-08-01 23:13:51 -04:00
|
|
|
]);
|
2018-04-03 20:00:21 -04:00
|
|
|
|
2020-02-04 09:10:53 +01:00
|
|
|
assert!(utils::compare_output(
|
2018-08-01 23:13:51 -04:00
|
|
|
app,
|
|
|
|
"test -h",
|
|
|
|
HIDDEN_LONG_ARGS_SHORT_HELP,
|
|
|
|
false
|
|
|
|
));
|
|
|
|
}
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
static HIDDEN_POS_ARGS: &str = "test 1.4
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test [another]
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<another> another pos
|
|
|
|
|
2021-10-11 17:01:33 -05:00
|
|
|
OPTIONS:
|
2021-10-08 13:05:40 -04:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2021-09-24 11:58:39 -04:00
|
|
|
";
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hidden_pos_args() {
|
2021-10-08 13:05:40 -04:00
|
|
|
let app = App::new("test").version("1.4").args(&[
|
|
|
|
Arg::new("pos").about("some pos").hidden(true),
|
|
|
|
Arg::new("another").about("another pos"),
|
|
|
|
]);
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
assert!(utils::compare_output(
|
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
HIDDEN_POS_ARGS,
|
|
|
|
false
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
static HIDDEN_SUBCMDS: &str = "test 1.4
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test
|
|
|
|
|
2021-10-11 17:01:33 -05:00
|
|
|
OPTIONS:
|
2021-10-08 13:05:40 -04:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2021-09-24 11:58:39 -04:00
|
|
|
";
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hidden_subcmds() {
|
|
|
|
let app = App::new("test")
|
|
|
|
.version("1.4")
|
|
|
|
.subcommand(App::new("sub").setting(AppSettings::Hidden));
|
|
|
|
|
|
|
|
assert!(utils::compare_output(
|
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
HIDDEN_SUBCMDS,
|
|
|
|
false
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
static HIDDEN_OPT_ARGS_ONLY: &str = "test 1.4
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test
|
|
|
|
|
2021-09-24 11:58:39 -04:00
|
|
|
After help
|
|
|
|
";
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hidden_opt_args_only() {
|
|
|
|
let app = App::new("test")
|
|
|
|
.version("1.4")
|
|
|
|
.after_help("After help")
|
|
|
|
.mut_arg("help", |a| a.hidden(true))
|
2021-10-08 13:05:40 -04:00
|
|
|
.mut_arg("version", |a| a.hidden(true))
|
2021-02-08 03:33:57 +00:00
|
|
|
.args(&[Arg::from("--option [opt] 'some option'").hidden(true)]);
|
|
|
|
|
|
|
|
assert!(utils::compare_output(
|
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
HIDDEN_OPT_ARGS_ONLY,
|
|
|
|
false
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
static HIDDEN_POS_ARGS_ONLY: &str = "test 1.4
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test
|
|
|
|
|
2021-09-24 11:58:39 -04:00
|
|
|
After help
|
|
|
|
";
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hidden_pos_args_only() {
|
|
|
|
let app = App::new("test")
|
|
|
|
.version("1.4")
|
|
|
|
.after_help("After help")
|
|
|
|
.mut_arg("help", |a| a.hidden(true))
|
2021-10-08 13:05:40 -04:00
|
|
|
.mut_arg("version", |a| a.hidden(true))
|
2021-02-08 03:33:57 +00:00
|
|
|
.args(&[Arg::new("pos").about("some pos").hidden(true)]);
|
|
|
|
|
|
|
|
assert!(utils::compare_output(
|
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
HIDDEN_POS_ARGS_ONLY,
|
|
|
|
false
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
static HIDDEN_SUBCMDS_ONLY: &str = "test 1.4
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test
|
|
|
|
|
2021-09-24 11:58:39 -04:00
|
|
|
After help
|
|
|
|
";
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hidden_subcmds_only() {
|
|
|
|
let app = App::new("test")
|
|
|
|
.version("1.4")
|
|
|
|
.after_help("After help")
|
|
|
|
.mut_arg("help", |a| a.hidden(true))
|
2021-10-08 13:05:40 -04:00
|
|
|
.mut_arg("version", |a| a.hidden(true))
|
2021-02-08 03:33:57 +00:00
|
|
|
.subcommand(App::new("sub").setting(AppSettings::Hidden));
|
|
|
|
|
|
|
|
assert!(utils::compare_output(
|
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
HIDDEN_SUBCMDS_ONLY,
|
|
|
|
false
|
|
|
|
));
|
|
|
|
}
|