2022-06-07 21:21:12 +00:00
|
|
|
use super::utils;
|
2015-10-01 03:34:23 +00:00
|
|
|
|
2023-02-15 16:25:19 +00:00
|
|
|
use clap::{arg, builder::PossibleValue, Arg, ArgAction, Command};
|
2015-10-01 03:34:23 +00:00
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static HIDDEN_ARGS: &str = "\
|
2015-10-01 03:34:23 +00:00
|
|
|
tests stuff
|
|
|
|
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: test [OPTIONS]
|
2015-10-01 03:34:23 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2022-09-07 20:29:15 +00:00
|
|
|
-F, --flag2 some other flag
|
|
|
|
--option <opt> some option
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
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() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2017-01-03 04:05:23 +00:00
|
|
|
.author("Kevin K.")
|
|
|
|
.about("tests stuff")
|
2017-03-03 08:32:09 +00:00
|
|
|
.version("1.4")
|
2022-11-24 13:54:25 +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"),
|
2022-09-12 21:59:57 +00:00
|
|
|
arg!(--option <opt> "some option"),
|
2021-11-29 16:45:30 +00:00
|
|
|
Arg::new("DUMMY").hide(true),
|
2018-01-25 04:05:05 +00:00
|
|
|
]);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", HIDDEN_ARGS, false);
|
2015-10-01 03:34:23 +00:00
|
|
|
}
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static HIDDEN_SHORT_ARGS: &str = "\
|
2018-04-04 00:00:21 +00:00
|
|
|
hides short args
|
|
|
|
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: test [OPTIONS]
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2022-09-07 20:29:15 +00:00
|
|
|
-v, --visible This text should be visible
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help (see more with '--help')
|
|
|
|
-V, --version Print version
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
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() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2018-04-04 00:00:21 +00:00
|
|
|
.about("hides short args")
|
|
|
|
.author("Steve P.")
|
|
|
|
.version("2.31.2")
|
2022-11-24 13:54:25 +00:00
|
|
|
.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)
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::SetTrue)
|
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")
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::SetTrue)
|
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
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "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() {
|
2022-08-31 14:29:00 +00:00
|
|
|
static HIDDEN_SHORT_ARGS_LONG_HELP: &str = "\
|
2022-07-22 20:43:49 +00:00
|
|
|
hides short args
|
|
|
|
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: test [OPTIONS]
|
2022-07-22 20:43:49 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2022-09-07 20:29:15 +00:00
|
|
|
-c, --config
|
|
|
|
Some help text describing the --config arg
|
2022-07-22 20:43:49 +00:00
|
|
|
|
2022-09-07 20:29:15 +00:00
|
|
|
-v, --visible
|
|
|
|
This text should be visible
|
2022-07-22 20:43:49 +00:00
|
|
|
|
2022-09-07 20:29:15 +00:00
|
|
|
-h, --help
|
2023-01-03 16:49:43 +00:00
|
|
|
Print help (see a summary with '-h')
|
2022-07-22 20:43:49 +00:00
|
|
|
|
2022-09-07 20:29:15 +00:00
|
|
|
-V, --version
|
2023-01-03 16:49:43 +00:00
|
|
|
Print version
|
2022-07-22 20:43:49 +00:00
|
|
|
";
|
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2018-04-04 00:00:21 +00:00
|
|
|
.about("hides short args")
|
|
|
|
.author("Steve P.")
|
|
|
|
.version("2.31.2")
|
2022-11-24 13:54:25 +00:00
|
|
|
.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)
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::SetTrue)
|
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")
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::SetTrue)
|
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
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", HIDDEN_SHORT_ARGS_LONG_HELP, false);
|
2018-04-04 00:00:21 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static HIDDEN_LONG_ARGS: &str = "\
|
2018-04-04 00:00:21 +00:00
|
|
|
hides long args
|
|
|
|
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: test [OPTIONS]
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2022-09-07 20:29:15 +00:00
|
|
|
-v, --visible
|
|
|
|
This text should be visible
|
2020-10-10 15:11:42 +00:00
|
|
|
|
2022-09-07 20:29:15 +00:00
|
|
|
-h, --help
|
2023-01-03 16:49:43 +00:00
|
|
|
Print help (see a summary with '-h')
|
2022-07-22 20:43:49 +00:00
|
|
|
|
2022-09-07 20:29:15 +00:00
|
|
|
-V, --version
|
2023-01-03 16:49:43 +00:00
|
|
|
Print version
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2018-04-04 00:00:21 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn hide_long_args() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2018-04-04 00:00:21 +00:00
|
|
|
.about("hides long args")
|
|
|
|
.author("Steve P.")
|
|
|
|
.version("2.31.2")
|
2022-11-24 13:54:25 +00:00
|
|
|
.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)
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::SetTrue)
|
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")
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::SetTrue)
|
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
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", HIDDEN_LONG_ARGS, false);
|
2018-04-04 00:00:21 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static HIDDEN_LONG_ARGS_SHORT_HELP: &str = "\
|
2018-04-04 00:00:21 +00:00
|
|
|
hides long args
|
|
|
|
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: test [OPTIONS]
|
2018-04-04 00:00:21 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2022-09-07 20:29:15 +00:00
|
|
|
-c, --config Some help text describing the --config arg
|
|
|
|
-v, --visible This text should be visible
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help (see more with '--help')
|
|
|
|
-V, --version Print version
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2018-04-04 00:00:21 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn hide_long_args_short_help() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2018-04-04 00:00:21 +00:00
|
|
|
.about("hides long args")
|
|
|
|
.author("Steve P.")
|
|
|
|
.version("2.31.2")
|
2022-11-24 13:54:25 +00:00
|
|
|
.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)
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::SetTrue)
|
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")
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::SetTrue)
|
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
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test -h", HIDDEN_LONG_ARGS_SHORT_HELP, false);
|
2018-08-02 03:13:51 +00:00
|
|
|
}
|
2021-02-08 03:33:57 +00:00
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static HIDDEN_POS_ARGS: &str = "\
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: test [another]
|
2021-02-08 03:33:57 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Arguments:
|
2022-09-07 20:29:15 +00:00
|
|
|
[another] another pos
|
2021-02-08 03:33:57 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
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() {
|
2022-11-24 13:54:25 +00:00
|
|
|
let cmd = Command::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
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", HIDDEN_POS_ARGS, false);
|
2021-02-08 03:33:57 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static HIDDEN_SUBCMDS: &str = "\
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: test
|
2021-02-08 03:33:57 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
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() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2021-02-08 03:33:57 +00:00
|
|
|
.version("1.4")
|
2022-02-12 03:48:29 +00:00
|
|
|
.subcommand(Command::new("sub").hide(true));
|
2021-02-08 03:33:57 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", HIDDEN_SUBCMDS, false);
|
2021-02-08 03:33:57 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static HIDDEN_OPT_ARGS_ONLY: &str = "\
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: test
|
2021-02-08 03:33:57 +00:00
|
|
|
|
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() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2021-02-08 03:33:57 +00:00
|
|
|
.version("1.4")
|
|
|
|
.after_help("After help")
|
2022-08-08 21:08:47 +00:00
|
|
|
.disable_help_flag(true)
|
|
|
|
.disable_version_flag(true)
|
2022-08-10 20:13:44 +00:00
|
|
|
.arg(arg!(-h - -help).action(ArgAction::Help).hide(true))
|
2022-08-08 21:08:47 +00:00
|
|
|
.arg(arg!(-v - -version).hide(true))
|
2022-09-12 21:59:57 +00:00
|
|
|
.arg(arg!(--option <opt> "some option").hide(true));
|
2021-02-08 03:33:57 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", HIDDEN_OPT_ARGS_ONLY, false);
|
2021-02-08 03:33:57 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static HIDDEN_POS_ARGS_ONLY: &str = "\
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: test
|
2021-02-08 03:33:57 +00:00
|
|
|
|
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() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2021-02-08 03:33:57 +00:00
|
|
|
.version("1.4")
|
|
|
|
.after_help("After help")
|
2022-08-08 21:08:47 +00:00
|
|
|
.disable_help_flag(true)
|
|
|
|
.disable_version_flag(true)
|
2022-08-10 20:13:44 +00:00
|
|
|
.arg(arg!(-h - -help).action(ArgAction::Help).hide(true))
|
2022-08-08 21:08:47 +00:00
|
|
|
.arg(arg!(-v - -version).hide(true))
|
2022-11-24 13:54:25 +00:00
|
|
|
.args([Arg::new("pos").help("some pos").hide(true)]);
|
2021-02-08 03:33:57 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", HIDDEN_POS_ARGS_ONLY, false);
|
2021-02-08 03:33:57 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static HIDDEN_SUBCMDS_ONLY: &str = "\
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: test
|
2021-02-08 03:33:57 +00:00
|
|
|
|
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() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2021-02-08 03:33:57 +00:00
|
|
|
.version("1.4")
|
|
|
|
.after_help("After help")
|
2022-08-08 21:08:47 +00:00
|
|
|
.disable_help_flag(true)
|
|
|
|
.disable_version_flag(true)
|
2022-08-10 20:13:44 +00:00
|
|
|
.arg(arg!(-h - -help).action(ArgAction::Help).hide(true))
|
2022-08-08 21:08:47 +00:00
|
|
|
.arg(arg!(-v - -version).hide(true))
|
2022-02-12 03:48:29 +00:00
|
|
|
.subcommand(Command::new("sub").hide(true));
|
2021-02-08 03:33:57 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", HIDDEN_SUBCMDS_ONLY, false);
|
2021-02-08 03:33:57 +00:00
|
|
|
}
|
2023-02-15 16:25:19 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hidden_arg_with_possible_value_with_help() {
|
|
|
|
// Normally the presence of a possible value with a help text triggers a
|
|
|
|
// change of the --help help text by appending `(see more with '--help')`
|
|
|
|
// or `(see a summary with '-h')`. When the argument is completely hidden
|
|
|
|
// we however do not want it to trigger that change.
|
|
|
|
static POS_VALS_HELP: &str = "\
|
|
|
|
Usage: ctest
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-h, --help Print help
|
|
|
|
";
|
|
|
|
let app = Command::new("ctest").arg(
|
|
|
|
Arg::new("pos")
|
|
|
|
.hide(true)
|
|
|
|
.value_parser([
|
|
|
|
PossibleValue::new("fast"),
|
|
|
|
PossibleValue::new("slow").help("not as fast"),
|
|
|
|
])
|
|
|
|
.action(ArgAction::Set),
|
|
|
|
);
|
|
|
|
utils::assert_output(app, "ctest --help", POS_VALS_HELP, false);
|
|
|
|
}
|