2021-11-30 15:31:19 +00:00
|
|
|
use crate::utils;
|
2015-10-01 03:34:23 +00:00
|
|
|
|
2021-11-19 20:33:11 +00:00
|
|
|
use clap::{arg, App, AppSettings, Arg};
|
2015-10-01 03:34:23 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static HIDDEN_ARGS: &str = "test 1.4
|
2015-10-01 03:34:23 +00:00
|
|
|
Kevin K.
|
|
|
|
tests stuff
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
test [OPTIONS]
|
2015-10-01 03:34:23 +00:00
|
|
|
|
|
|
|
OPTIONS:
|
2021-10-11 22:01:33 +00:00
|
|
|
-F, --flag2 some other flag
|
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
--option <opt> some option
|
2021-10-11 22:01:33 +00:00
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2017-01-03 04:05:23 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn hide_args() {
|
2017-01-03 04:05:23 +00:00
|
|
|
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(&[
|
2021-11-29 16:45:30 +00:00
|
|
|
arg!(-f --flag "some flag").hide(true),
|
2021-11-19 20:33:11 +00:00
|
|
|
arg!(-F --flag2 "some other flag"),
|
|
|
|
arg!(--option <opt> "some option").required(false),
|
2021-11-29 16:45:30 +00:00
|
|
|
Arg::new("DUMMY").hide(true),
|
2018-01-25 04:05:05 +00:00
|
|
|
]);
|
2020-02-04 08:10:53 +00:00
|
|
|
assert!(utils::compare_output(
|
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
HIDDEN_ARGS,
|
|
|
|
false
|
|
|
|
));
|
2015-10-01 03:34:23 +00:00
|
|
|
}
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static HIDDEN_SHORT_ARGS: &str = "test 2.31.2
|
2018-04-04 00:00:21 +00:00
|
|
|
Steve P.
|
|
|
|
hides short args
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
test [OPTIONS]
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2020-10-10 15:11:42 +00:00
|
|
|
-v, --visible This text should be visible
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static HIDDEN_SHORT_ARGS_LONG_HELP: &str = "test 2.31.2
|
2018-04-04 00:00:21 +00:00
|
|
|
Steve P.
|
|
|
|
hides short args
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
test [OPTIONS]
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2020-08-20 12:45:38 +00:00
|
|
|
-c, --config
|
2018-04-04 00:00:21 +00:00
|
|
|
Some help text describing the --config arg
|
|
|
|
|
2020-08-20 12:45:38 +00:00
|
|
|
-h, --help
|
2021-07-30 03:23:25 +00:00
|
|
|
Print help information
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2020-08-20 12:45:38 +00:00
|
|
|
-v, --visible
|
2020-10-10 15:11:42 +00:00
|
|
|
This text should be visible
|
|
|
|
|
|
|
|
-V, --version
|
2021-09-24 15:58:39 +00:00
|
|
|
Print version information
|
|
|
|
";
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2021-11-29 16:45:30 +00:00
|
|
|
/// Ensure hide with short option
|
2018-04-04 00:00:21 +00:00
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn hide_short_args() {
|
2018-04-04 00:00:21 +00:00
|
|
|
let app = App::new("test")
|
|
|
|
.about("hides short args")
|
|
|
|
.author("Steve P.")
|
|
|
|
.version("2.31.2")
|
|
|
|
.args(&[
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("cfg")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('c')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("config")
|
2021-11-29 16:45:30 +00:00
|
|
|
.hide_short_help(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Some help text describing the --config arg"),
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("visible")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('v')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("visible")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("This text should be visible"),
|
2018-08-02 03:13:51 +00:00
|
|
|
]);
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2020-02-04 08:10:53 +00:00
|
|
|
assert!(utils::compare_output(
|
2018-08-02 03:13:51 +00:00
|
|
|
app,
|
|
|
|
"test -h",
|
|
|
|
HIDDEN_SHORT_ARGS,
|
|
|
|
false
|
|
|
|
));
|
2018-04-04 00:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Ensure visible with opposite option
|
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn hide_short_args_long_help() {
|
2018-04-04 00:00:21 +00:00
|
|
|
let app = App::new("test")
|
|
|
|
.about("hides short args")
|
|
|
|
.author("Steve P.")
|
|
|
|
.version("2.31.2")
|
|
|
|
.args(&[
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("cfg")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('c')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("config")
|
2021-11-29 16:45:30 +00:00
|
|
|
.hide_short_help(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Some help text describing the --config arg"),
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("visible")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('v')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("visible")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("This text should be visible"),
|
2018-08-02 03:13:51 +00:00
|
|
|
]);
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2020-02-04 08:10:53 +00:00
|
|
|
assert!(utils::compare_output(
|
2018-08-02 03:13:51 +00:00
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
HIDDEN_SHORT_ARGS_LONG_HELP,
|
|
|
|
false
|
|
|
|
));
|
2018-04-04 00:00:21 +00:00
|
|
|
}
|
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static HIDDEN_LONG_ARGS: &str = "test 2.31.2
|
2018-04-04 00:00:21 +00:00
|
|
|
Steve P.
|
|
|
|
hides long args
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
test [OPTIONS]
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2020-08-20 12:45:38 +00:00
|
|
|
-h, --help
|
2021-07-30 03:23:25 +00:00
|
|
|
Print help information
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2020-08-20 12:45:38 +00:00
|
|
|
-v, --visible
|
2020-10-10 15:11:42 +00:00
|
|
|
This text should be visible
|
|
|
|
|
|
|
|
-V, --version
|
2021-09-24 15:58:39 +00:00
|
|
|
Print version information
|
|
|
|
";
|
2018-04-04 00:00:21 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn hide_long_args() {
|
2018-04-04 00:00:21 +00:00
|
|
|
let app = App::new("test")
|
|
|
|
.about("hides long args")
|
|
|
|
.author("Steve P.")
|
|
|
|
.version("2.31.2")
|
|
|
|
.args(&[
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("cfg")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('c')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("config")
|
2021-11-29 16:45:30 +00:00
|
|
|
.hide_long_help(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Some help text describing the --config arg"),
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("visible")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('v')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("visible")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("This text should be visible"),
|
2018-08-02 03:13:51 +00:00
|
|
|
]);
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2020-02-04 08:10:53 +00:00
|
|
|
assert!(utils::compare_output(
|
2018-08-02 03:13:51 +00:00
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
HIDDEN_LONG_ARGS,
|
|
|
|
false
|
|
|
|
));
|
2018-04-04 00:00:21 +00:00
|
|
|
}
|
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static HIDDEN_LONG_ARGS_SHORT_HELP: &str = "test 2.31.2
|
2018-04-04 00:00:21 +00:00
|
|
|
Steve P.
|
|
|
|
hides long args
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
test [OPTIONS]
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2018-04-04 00:00:21 +00:00
|
|
|
-c, --config Some help text describing the --config arg
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2020-10-10 15:11:42 +00:00
|
|
|
-v, --visible This text should be visible
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2018-04-04 00:00:21 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn hide_long_args_short_help() {
|
2018-04-04 00:00:21 +00:00
|
|
|
let app = App::new("test")
|
|
|
|
.about("hides long args")
|
|
|
|
.author("Steve P.")
|
|
|
|
.version("2.31.2")
|
|
|
|
.args(&[
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("cfg")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('c')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("config")
|
2021-11-29 16:45:30 +00:00
|
|
|
.hide_long_help(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Some help text describing the --config arg"),
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("visible")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('v')
|
2018-04-04 00:00:21 +00:00
|
|
|
.long("visible")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("This text should be visible"),
|
2018-08-02 03:13:51 +00:00
|
|
|
]);
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2020-02-04 08:10:53 +00:00
|
|
|
assert!(utils::compare_output(
|
2018-08-02 03:13:51 +00: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 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-10-08 17:05:40 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn hide_pos_args() {
|
2021-10-08 17:05:40 +00:00
|
|
|
let app = App::new("test").version("1.4").args(&[
|
2021-11-29 16:45:30 +00:00
|
|
|
Arg::new("pos").help("some pos").hide(true),
|
2021-11-18 16:17:15 +00:00
|
|
|
Arg::new("another").help("another pos"),
|
2021-10-08 17:05:40 +00:00
|
|
|
]);
|
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 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-10-08 17:05:40 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn hide_subcmds() {
|
2021-02-08 03:33:57 +00:00
|
|
|
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 15:58:39 +00:00
|
|
|
After help
|
|
|
|
";
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn hide_opt_args_only() {
|
2021-02-08 03:33:57 +00:00
|
|
|
let app = App::new("test")
|
|
|
|
.version("1.4")
|
|
|
|
.after_help("After help")
|
2021-11-29 16:45:30 +00:00
|
|
|
.mut_arg("help", |a| a.hide(true))
|
|
|
|
.mut_arg("version", |a| a.hide(true))
|
2021-11-19 20:33:11 +00:00
|
|
|
.arg(
|
|
|
|
arg!(--option <opt> "some option")
|
|
|
|
.required(false)
|
2021-11-29 16:45:30 +00:00
|
|
|
.hide(true),
|
2021-11-19 20:33:11 +00:00
|
|
|
);
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
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 15:58:39 +00:00
|
|
|
After help
|
|
|
|
";
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn hide_pos_args_only() {
|
2021-02-08 03:33:57 +00:00
|
|
|
let app = App::new("test")
|
|
|
|
.version("1.4")
|
|
|
|
.after_help("After help")
|
2021-11-29 16:45:30 +00:00
|
|
|
.mut_arg("help", |a| a.hide(true))
|
|
|
|
.mut_arg("version", |a| a.hide(true))
|
|
|
|
.args(&[Arg::new("pos").help("some pos").hide(true)]);
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
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 15:58:39 +00:00
|
|
|
After help
|
|
|
|
";
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn hide_subcmds_only() {
|
2021-02-08 03:33:57 +00:00
|
|
|
let app = App::new("test")
|
|
|
|
.version("1.4")
|
|
|
|
.after_help("After help")
|
2021-11-29 16:45:30 +00:00
|
|
|
.mut_arg("help", |a| a.hide(true))
|
|
|
|
.mut_arg("version", |a| a.hide(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
|
|
|
|
));
|
|
|
|
}
|