2022-06-07 16:21:12 -05:00
|
|
|
use super::utils;
|
2016-04-09 21:35:24 -03:00
|
|
|
|
2022-02-11 21:48:29 -06:00
|
|
|
use clap::{arg, Command};
|
2016-04-09 21:35:24 -03:00
|
|
|
|
2022-12-22 00:47:53 +09:00
|
|
|
#[cfg(not(feature = "unstable-v5"))]
|
|
|
|
static EXAMPLE1_TMPL_S: &str = "{bin} {version}
|
|
|
|
{author}
|
|
|
|
{about}
|
|
|
|
|
|
|
|
Usage: {usage}
|
|
|
|
|
|
|
|
{all-args}";
|
|
|
|
|
|
|
|
#[cfg(feature = "unstable-v5")]
|
2022-12-21 09:58:03 +09:00
|
|
|
static EXAMPLE1_TMPL_S: &str = "{name} {version}
|
2020-02-04 09:10:53 +01:00
|
|
|
{author}
|
|
|
|
{about}
|
2017-01-02 23:05:23 -05:00
|
|
|
|
2022-09-07 11:03:55 -05:00
|
|
|
Usage: {usage}
|
2020-02-04 09:10:53 +01:00
|
|
|
|
|
|
|
{all-args}";
|
|
|
|
|
2022-12-22 00:47:53 +09:00
|
|
|
#[cfg(not(feature = "unstable-v5"))]
|
|
|
|
static EXAMPLE1_TMPS_F: &str = "{bin} {version}
|
|
|
|
{author}
|
|
|
|
{about}
|
|
|
|
|
|
|
|
Usage: {usage}
|
|
|
|
|
|
|
|
Options:
|
|
|
|
{options}
|
|
|
|
Arguments:
|
|
|
|
{positionals}
|
|
|
|
Commands:
|
|
|
|
{subcommands}";
|
|
|
|
|
|
|
|
#[cfg(feature = "unstable-v5")]
|
2022-12-21 09:58:03 +09:00
|
|
|
static EXAMPLE1_TMPS_F: &str = "{name} {version}
|
2020-02-04 09:10:53 +01:00
|
|
|
{author}
|
|
|
|
{about}
|
|
|
|
|
2022-09-07 11:03:55 -05:00
|
|
|
Usage: {usage}
|
2020-02-04 09:10:53 +01:00
|
|
|
|
2022-08-26 09:40:23 -05:00
|
|
|
Options:
|
2020-02-04 09:10:53 +01:00
|
|
|
{options}
|
2022-08-26 09:40:23 -05:00
|
|
|
Arguments:
|
2020-02-04 09:10:53 +01:00
|
|
|
{positionals}
|
2022-08-30 21:38:37 -05:00
|
|
|
Commands:
|
2020-02-04 09:10:53 +01:00
|
|
|
{subcommands}";
|
2016-04-09 21:35:24 -03:00
|
|
|
|
2019-10-02 16:27:19 +03:00
|
|
|
static CUSTOM_TEMPL_HELP: &str = "MyApp 1.0
|
2016-05-30 05:39:54 -04:00
|
|
|
Kevin K. <kbknapp@gmail.com>
|
|
|
|
Does awesome things
|
|
|
|
|
2022-09-07 11:03:55 -05:00
|
|
|
Usage: MyApp [OPTIONS] <output> [COMMAND]
|
2016-05-30 05:39:54 -04:00
|
|
|
|
2022-08-26 09:40:23 -05:00
|
|
|
Options:
|
2022-09-07 15:29:15 -05:00
|
|
|
-c, --config <FILE> Sets a custom config file
|
|
|
|
-d... Turn debugging information on
|
2023-01-03 10:49:43 -06:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
2022-08-26 09:40:23 -05:00
|
|
|
Arguments:
|
2022-09-07 15:29:15 -05:00
|
|
|
<output> Sets an optional output file
|
2022-08-30 21:38:37 -05:00
|
|
|
Commands:
|
2022-09-07 15:29:15 -05:00
|
|
|
test does testing things
|
|
|
|
help Print this message or the help of the given subcommand(s)
|
2021-09-24 11:58:39 -04:00
|
|
|
";
|
2016-05-30 05:39:54 -04:00
|
|
|
|
2019-10-02 16:27:19 +03:00
|
|
|
static SIMPLE_TEMPLATE: &str = "MyApp 1.0
|
2016-05-30 05:39:54 -04:00
|
|
|
Kevin K. <kbknapp@gmail.com>
|
|
|
|
Does awesome things
|
|
|
|
|
2022-09-07 11:03:55 -05:00
|
|
|
Usage: MyApp [OPTIONS] <output> [COMMAND]
|
2016-05-30 05:39:54 -04:00
|
|
|
|
2022-08-30 21:38:37 -05:00
|
|
|
Commands:
|
2022-09-07 15:29:15 -05:00
|
|
|
test does testing things
|
|
|
|
help Print this message or the help of the given subcommand(s)
|
2022-08-26 10:59:27 -05:00
|
|
|
|
2022-08-26 09:40:23 -05:00
|
|
|
Arguments:
|
2022-09-07 15:29:15 -05:00
|
|
|
<output> Sets an optional output file
|
2018-03-07 06:23:20 -05:00
|
|
|
|
2022-08-26 09:40:23 -05:00
|
|
|
Options:
|
2022-09-07 15:29:15 -05:00
|
|
|
-c, --config <FILE> Sets a custom config file
|
|
|
|
-d... Turn debugging information on
|
2023-01-03 10:49:43 -06:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
2021-09-24 11:58:39 -04:00
|
|
|
";
|
2016-05-30 05:39:54 -04:00
|
|
|
|
2016-04-09 21:35:24 -03:00
|
|
|
#[test]
|
2016-05-30 05:39:54 -04:00
|
|
|
fn with_template() {
|
2022-02-14 15:47:20 -06:00
|
|
|
let cmd = get_app().help_template(EXAMPLE1_TMPL_S);
|
2022-04-29 15:32:25 -05:00
|
|
|
utils::assert_output(cmd, "MyApp --help", SIMPLE_TEMPLATE, false);
|
2016-05-30 05:39:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn custom_template() {
|
2022-02-14 15:47:20 -06:00
|
|
|
let cmd = get_app().help_template(EXAMPLE1_TMPS_F);
|
2022-04-29 15:32:25 -05:00
|
|
|
utils::assert_output(cmd, "MyApp --help", CUSTOM_TEMPL_HELP, false);
|
2016-04-09 21:35:24 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn template_empty() {
|
2022-02-14 15:47:20 -06:00
|
|
|
let cmd = Command::new("MyApp")
|
2018-01-24 23:05:05 -05:00
|
|
|
.version("1.0")
|
|
|
|
.author("Kevin K. <kbknapp@gmail.com>")
|
|
|
|
.about("Does awesome things")
|
2018-10-19 16:42:13 -04:00
|
|
|
.help_template("");
|
2022-04-29 15:32:25 -05:00
|
|
|
utils::assert_output(cmd, "MyApp --help", "\n", false);
|
2016-04-09 21:35:24 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn template_notag() {
|
2022-02-14 15:47:20 -06:00
|
|
|
let cmd = Command::new("MyApp")
|
2018-01-24 23:05:05 -05:00
|
|
|
.version("1.0")
|
|
|
|
.author("Kevin K. <kbknapp@gmail.com>")
|
|
|
|
.about("Does awesome things")
|
2018-10-19 16:42:13 -04:00
|
|
|
.help_template("test no tag test");
|
2022-04-29 15:32:25 -05:00
|
|
|
utils::assert_output(cmd, "MyApp --help", "test no tag test\n", false);
|
2016-04-09 21:35:24 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn template_unknowntag() {
|
2022-02-14 15:47:20 -06:00
|
|
|
let cmd = Command::new("MyApp")
|
2018-01-24 23:05:05 -05:00
|
|
|
.version("1.0")
|
|
|
|
.author("Kevin K. <kbknapp@gmail.com>")
|
|
|
|
.about("Does awesome things")
|
2018-10-19 16:42:13 -04:00
|
|
|
.help_template("test {unknown_tag} test");
|
2022-04-29 15:32:25 -05:00
|
|
|
utils::assert_output(cmd, "MyApp --help", "test {unknown_tag} test\n", false);
|
2016-04-09 21:35:24 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn template_author_version() {
|
2022-12-22 00:47:53 +09:00
|
|
|
#[cfg(not(feature = "unstable-v5"))]
|
|
|
|
let cmd = Command::new("MyApp")
|
|
|
|
.version("1.0")
|
|
|
|
.author("Kevin K. <kbknapp@gmail.com>")
|
|
|
|
.about("Does awesome things")
|
|
|
|
.help_template("{author}\n{version}\n{about}\n{bin}");
|
|
|
|
|
|
|
|
#[cfg(feature = "unstable-v5")]
|
2022-02-14 15:47:20 -06:00
|
|
|
let cmd = Command::new("MyApp")
|
2018-01-24 23:05:05 -05:00
|
|
|
.version("1.0")
|
|
|
|
.author("Kevin K. <kbknapp@gmail.com>")
|
|
|
|
.about("Does awesome things")
|
2022-12-21 09:58:03 +09:00
|
|
|
.help_template("{author}\n{version}\n{about}\n{name}");
|
2022-12-22 00:47:53 +09:00
|
|
|
|
2022-04-29 15:32:25 -05:00
|
|
|
utils::assert_output(
|
2022-02-14 15:47:20 -06:00
|
|
|
cmd,
|
2018-01-24 23:05:05 -05:00
|
|
|
"MyApp --help",
|
2021-09-24 11:58:39 -04:00
|
|
|
"Kevin K. <kbknapp@gmail.com>\n1.0\nDoes awesome things\nMyApp\n",
|
2022-04-29 15:32:25 -05:00
|
|
|
false,
|
|
|
|
);
|
2016-04-09 21:35:24 -03:00
|
|
|
}
|
|
|
|
|
2017-01-02 23:05:23 -05:00
|
|
|
// ----------
|
|
|
|
|
2022-08-15 14:29:46 -05:00
|
|
|
fn get_app() -> Command {
|
2022-02-11 21:48:29 -06:00
|
|
|
Command::new("MyApp")
|
2016-04-09 21:35:24 -03:00
|
|
|
.version("1.0")
|
|
|
|
.author("Kevin K. <kbknapp@gmail.com>")
|
|
|
|
.about("Does awesome things")
|
2021-11-19 14:33:11 -06:00
|
|
|
.arg(
|
|
|
|
arg!(
|
|
|
|
-c --config <FILE> "Sets a custom config file"
|
|
|
|
)
|
|
|
|
.required(false),
|
|
|
|
)
|
|
|
|
.arg(arg!(
|
|
|
|
<output> "Sets an optional output file"
|
2021-11-18 14:17:31 -06:00
|
|
|
))
|
2021-11-19 14:33:11 -06:00
|
|
|
.arg(arg!(
|
|
|
|
d: -d ... "Turn debugging information on"
|
2021-11-18 14:17:31 -06:00
|
|
|
))
|
2018-01-24 23:05:05 -05:00
|
|
|
.subcommand(
|
2022-02-11 21:48:29 -06:00
|
|
|
Command::new("test")
|
2018-01-24 23:05:05 -05:00
|
|
|
.about("does testing things")
|
2021-11-19 14:33:11 -06:00
|
|
|
.arg(arg!(-l --list "lists test values")),
|
2018-01-24 23:05:05 -05:00
|
|
|
)
|
2016-04-09 21:35:24 -03:00
|
|
|
}
|