clap/tests/builder/hidden_args.rs

291 lines
6.6 KiB
Rust
Raw Normal View History

use super::utils;
2015-10-01 03:34:23 +00:00
2022-02-12 03:48:29 +00:00
use clap::{arg, Arg, Command};
2015-10-01 03:34:23 +00:00
static HIDDEN_ARGS: &str = "test 1.4
2015-10-01 03:34:23 +00:00
Kevin K.
tests stuff
USAGE:
test [OPTIONS]
2015-10-01 03:34:23 +00:00
OPTIONS:
-F, --flag2 some other flag
-h, --help Print help information
--option <opt> some option
-V, --version Print version information
";
#[test]
fn hide_args() {
2022-02-14 21:47:20 +00:00
let cmd = Command::new("test")
.author("Kevin K.")
.about("tests stuff")
.version("1.4")
2018-01-25 04:05:05 +00:00
.args(&[
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),
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
}
static HIDDEN_SHORT_ARGS: &str = "test 2.31.2
Steve P.
hides short args
USAGE:
test [OPTIONS]
OPTIONS:
-h, --help Print help information
-v, --visible This text should be visible
-V, --version Print version information
";
static HIDDEN_SHORT_ARGS_LONG_HELP: &str = "test 2.31.2
Steve P.
hides short args
USAGE:
test [OPTIONS]
OPTIONS:
2020-08-20 12:45:38 +00:00
-c, --config
Some help text describing the --config arg
2020-08-20 12:45:38 +00:00
-h, --help
Print help information
2020-08-20 12:45:38 +00:00
-v, --visible
This text should be visible
-V, --version
Print version information
";
/// Ensure hide with short option
#[test]
fn hide_short_args() {
2022-02-14 21:47:20 +00:00
let cmd = Command::new("test")
.about("hides short args")
.author("Steve P.")
.version("2.31.2")
.args(&[
Arg::new("cfg")
.short('c')
.long("config")
.hide_short_help(true)
.help("Some help text describing the --config arg"),
Arg::new("visible")
.short('v')
.long("visible")
.help("This text should be visible"),
2018-08-02 03:13:51 +00:00
]);
2022-04-29 20:32:25 +00:00
utils::assert_output(cmd, "test -h", HIDDEN_SHORT_ARGS, false);
}
/// Ensure visible with opposite option
#[test]
fn hide_short_args_long_help() {
2022-02-14 21:47:20 +00:00
let cmd = Command::new("test")
.about("hides short args")
.author("Steve P.")
.version("2.31.2")
.args(&[
Arg::new("cfg")
.short('c')
.long("config")
.hide_short_help(true)
.help("Some help text describing the --config arg"),
Arg::new("visible")
.short('v')
.long("visible")
.help("This text should be visible"),
2018-08-02 03:13:51 +00:00
]);
2022-04-29 20:32:25 +00:00
utils::assert_output(cmd, "test --help", HIDDEN_SHORT_ARGS_LONG_HELP, false);
}
static HIDDEN_LONG_ARGS: &str = "test 2.31.2
Steve P.
hides long args
USAGE:
test [OPTIONS]
OPTIONS:
2020-08-20 12:45:38 +00:00
-h, --help
Print help information
2020-08-20 12:45:38 +00:00
-v, --visible
This text should be visible
-V, --version
Print version information
";
#[test]
fn hide_long_args() {
2022-02-14 21:47:20 +00:00
let cmd = Command::new("test")
.about("hides long args")
.author("Steve P.")
.version("2.31.2")
.args(&[
Arg::new("cfg")
.short('c')
.long("config")
.hide_long_help(true)
.help("Some help text describing the --config arg"),
Arg::new("visible")
.short('v')
.long("visible")
.help("This text should be visible"),
2018-08-02 03:13:51 +00:00
]);
2022-04-29 20:32:25 +00:00
utils::assert_output(cmd, "test --help", HIDDEN_LONG_ARGS, false);
}
static HIDDEN_LONG_ARGS_SHORT_HELP: &str = "test 2.31.2
Steve P.
hides long args
USAGE:
test [OPTIONS]
OPTIONS:
-c, --config Some help text describing the --config arg
-h, --help Print help information
-v, --visible This text should be visible
-V, --version Print version information
";
#[test]
fn hide_long_args_short_help() {
2022-02-14 21:47:20 +00:00
let cmd = Command::new("test")
.about("hides long args")
.author("Steve P.")
.version("2.31.2")
.args(&[
Arg::new("cfg")
.short('c')
.long("config")
.hide_long_help(true)
.help("Some help text describing the --config arg"),
Arg::new("visible")
.short('v')
.long("visible")
.help("This text should be visible"),
2018-08-02 03:13:51 +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
}
static HIDDEN_POS_ARGS: &str = "test 1.4
USAGE:
test [another]
ARGS:
<another> another pos
OPTIONS:
-h, --help Print help information
-V, --version Print version information
";
#[test]
fn hide_pos_args() {
2022-02-14 21:47:20 +00:00
let cmd = Command::new("test").version("1.4").args(&[
Arg::new("pos").help("some pos").hide(true),
Arg::new("another").help("another pos"),
]);
2022-04-29 20:32:25 +00:00
utils::assert_output(cmd, "test --help", HIDDEN_POS_ARGS, false);
}
static HIDDEN_SUBCMDS: &str = "test 1.4
USAGE:
test
OPTIONS:
-h, --help Print help information
-V, --version Print version information
";
#[test]
fn hide_subcmds() {
2022-02-14 21:47:20 +00:00
let cmd = Command::new("test")
.version("1.4")
2022-02-12 03:48:29 +00:00
.subcommand(Command::new("sub").hide(true));
2022-04-29 20:32:25 +00:00
utils::assert_output(cmd, "test --help", HIDDEN_SUBCMDS, false);
}
static HIDDEN_OPT_ARGS_ONLY: &str = "test 1.4
USAGE:
test
After help
";
#[test]
fn hide_opt_args_only() {
2022-02-14 21:47:20 +00:00
let cmd = Command::new("test")
.version("1.4")
.after_help("After help")
.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)
.hide(true),
2021-11-19 20:33:11 +00:00
);
2022-04-29 20:32:25 +00:00
utils::assert_output(cmd, "test --help", HIDDEN_OPT_ARGS_ONLY, false);
}
static HIDDEN_POS_ARGS_ONLY: &str = "test 1.4
USAGE:
test
After help
";
#[test]
fn hide_pos_args_only() {
2022-02-14 21:47:20 +00:00
let cmd = Command::new("test")
.version("1.4")
.after_help("After help")
.mut_arg("help", |a| a.hide(true))
.mut_arg("version", |a| a.hide(true))
.args(&[Arg::new("pos").help("some pos").hide(true)]);
2022-04-29 20:32:25 +00:00
utils::assert_output(cmd, "test --help", HIDDEN_POS_ARGS_ONLY, false);
}
static HIDDEN_SUBCMDS_ONLY: &str = "test 1.4
USAGE:
test
After help
";
#[test]
fn hide_subcmds_only() {
2022-02-14 21:47:20 +00:00
let cmd = Command::new("test")
.version("1.4")
.after_help("After help")
.mut_arg("help", |a| a.hide(true))
.mut_arg("version", |a| a.hide(true))
2022-02-12 03:48:29 +00:00
.subcommand(Command::new("sub").hide(true));
2022-04-29 20:32:25 +00:00
utils::assert_output(cmd, "test --help", HIDDEN_SUBCMDS_ONLY, false);
}