2020-02-04 08:10:53 +00:00
|
|
|
mod utils;
|
2016-04-10 00:35:24 +00:00
|
|
|
|
2018-11-14 17:05:06 +00:00
|
|
|
use clap::App;
|
2016-04-10 00:35:24 +00:00
|
|
|
|
2020-02-04 08:10:53 +00:00
|
|
|
static EXAMPLE1_TMPL_S: &str = "{bin} {version}
|
|
|
|
{author}
|
|
|
|
{about}
|
2017-01-03 04:05:23 +00:00
|
|
|
|
2020-02-04 08:10:53 +00:00
|
|
|
USAGE:
|
|
|
|
{usage}
|
|
|
|
|
|
|
|
{all-args}";
|
|
|
|
|
|
|
|
static EXAMPLE1_TMPS_F: &str = "{bin} {version}
|
|
|
|
{author}
|
|
|
|
{about}
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
{usage}
|
|
|
|
|
|
|
|
FLAGS:
|
|
|
|
{flags}
|
|
|
|
OPTIONS:
|
|
|
|
{options}
|
|
|
|
ARGS:
|
|
|
|
{positionals}
|
|
|
|
SUBCOMMANDS:
|
|
|
|
{subcommands}";
|
2016-04-10 00:35:24 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static CUSTOM_TEMPL_HELP: &str = "MyApp 1.0
|
2016-05-30 09:39:54 +00:00
|
|
|
Kevin K. <kbknapp@gmail.com>
|
|
|
|
Does awesome things
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
MyApp [FLAGS] [OPTIONS] <output> [SUBCOMMAND]
|
|
|
|
|
|
|
|
FLAGS:
|
2017-01-03 04:05:23 +00:00
|
|
|
-d Turn debugging information on
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2016-05-30 09:39:54 +00:00
|
|
|
OPTIONS:
|
|
|
|
-c, --config <FILE> Sets a custom config file
|
|
|
|
ARGS:
|
|
|
|
<output> Sets an optional output file
|
|
|
|
SUBCOMMANDS:
|
2021-07-30 03:23:25 +00:00
|
|
|
help Print this message or the help of the given subcommand(s)
|
2021-09-24 15:58:39 +00:00
|
|
|
test does testing things
|
|
|
|
";
|
2016-05-30 09:39:54 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static SIMPLE_TEMPLATE: &str = "MyApp 1.0
|
2016-05-30 09:39:54 +00:00
|
|
|
Kevin K. <kbknapp@gmail.com>
|
|
|
|
Does awesome things
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
MyApp [FLAGS] [OPTIONS] <output> [SUBCOMMAND]
|
|
|
|
|
2018-03-07 11:23:20 +00:00
|
|
|
ARGS:
|
|
|
|
<output> Sets an optional output file
|
|
|
|
|
2016-05-30 09:39:54 +00:00
|
|
|
FLAGS:
|
2017-01-03 04:05:23 +00:00
|
|
|
-d Turn debugging information on
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2016-05-30 09:39:54 +00:00
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-c, --config <FILE> Sets a custom config file
|
|
|
|
|
|
|
|
SUBCOMMANDS:
|
2021-07-30 03:23:25 +00:00
|
|
|
help Print this message or the help of the given subcommand(s)
|
2021-09-24 15:58:39 +00:00
|
|
|
test does testing things
|
|
|
|
";
|
2016-05-30 09:39:54 +00:00
|
|
|
|
2016-04-10 00:35:24 +00:00
|
|
|
#[test]
|
2016-05-30 09:39:54 +00:00
|
|
|
fn with_template() {
|
2020-02-04 08:10:53 +00:00
|
|
|
let app = get_app().help_template(EXAMPLE1_TMPL_S);
|
|
|
|
assert!(utils::compare_output(
|
2018-01-25 04:05:05 +00:00
|
|
|
app,
|
|
|
|
"MyApp --help",
|
|
|
|
SIMPLE_TEMPLATE,
|
|
|
|
false
|
|
|
|
));
|
2016-05-30 09:39:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn custom_template() {
|
2020-02-04 08:10:53 +00:00
|
|
|
let app = get_app().help_template(EXAMPLE1_TMPS_F);
|
|
|
|
assert!(utils::compare_output(
|
2018-01-25 04:05:05 +00:00
|
|
|
app,
|
|
|
|
"MyApp --help",
|
|
|
|
CUSTOM_TEMPL_HELP,
|
|
|
|
false
|
|
|
|
));
|
2016-04-10 00:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn template_empty() {
|
|
|
|
let app = App::new("MyApp")
|
2018-01-25 04:05:05 +00:00
|
|
|
.version("1.0")
|
|
|
|
.author("Kevin K. <kbknapp@gmail.com>")
|
|
|
|
.about("Does awesome things")
|
2018-10-19 20:42:13 +00:00
|
|
|
.help_template("");
|
2021-09-24 15:58:39 +00:00
|
|
|
assert!(utils::compare_output(app, "MyApp --help", "\n", false));
|
2016-04-10 00:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn template_notag() {
|
|
|
|
let app = App::new("MyApp")
|
2018-01-25 04:05:05 +00:00
|
|
|
.version("1.0")
|
|
|
|
.author("Kevin K. <kbknapp@gmail.com>")
|
|
|
|
.about("Does awesome things")
|
2018-10-19 20:42:13 +00:00
|
|
|
.help_template("test no tag test");
|
2020-02-04 08:10:53 +00:00
|
|
|
assert!(utils::compare_output(
|
2018-01-25 04:05:05 +00:00
|
|
|
app,
|
|
|
|
"MyApp --help",
|
2021-09-24 15:58:39 +00:00
|
|
|
"test no tag test\n",
|
2018-01-25 04:05:05 +00:00
|
|
|
false
|
|
|
|
));
|
2016-04-10 00:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn template_unknowntag() {
|
|
|
|
let app = App::new("MyApp")
|
2018-01-25 04:05:05 +00:00
|
|
|
.version("1.0")
|
|
|
|
.author("Kevin K. <kbknapp@gmail.com>")
|
|
|
|
.about("Does awesome things")
|
2018-10-19 20:42:13 +00:00
|
|
|
.help_template("test {unknown_tag} test");
|
2020-02-04 08:10:53 +00:00
|
|
|
assert!(utils::compare_output(
|
2018-01-25 04:05:05 +00:00
|
|
|
app,
|
|
|
|
"MyApp --help",
|
2021-09-24 15:58:39 +00:00
|
|
|
"test {unknown_tag} test\n",
|
2018-01-25 04:05:05 +00:00
|
|
|
false
|
|
|
|
));
|
2016-04-10 00:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn template_author_version() {
|
|
|
|
let app = App::new("MyApp")
|
2018-01-25 04:05:05 +00:00
|
|
|
.version("1.0")
|
|
|
|
.author("Kevin K. <kbknapp@gmail.com>")
|
|
|
|
.about("Does awesome things")
|
2018-10-19 20:42:13 +00:00
|
|
|
.help_template("{author}\n{version}\n{about}\n{bin}");
|
2020-02-04 08:10:53 +00:00
|
|
|
assert!(utils::compare_output(
|
2018-01-25 04:05:05 +00:00
|
|
|
app,
|
|
|
|
"MyApp --help",
|
2021-09-24 15:58:39 +00:00
|
|
|
"Kevin K. <kbknapp@gmail.com>\n1.0\nDoes awesome things\nMyApp\n",
|
2018-01-25 04:05:05 +00:00
|
|
|
false
|
|
|
|
));
|
2016-04-10 00:35:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-03 04:05:23 +00:00
|
|
|
// ----------
|
|
|
|
|
2020-02-04 08:10:53 +00:00
|
|
|
fn get_app() -> App<'static> {
|
2016-04-10 00:35:24 +00:00
|
|
|
App::new("MyApp")
|
|
|
|
.version("1.0")
|
|
|
|
.author("Kevin K. <kbknapp@gmail.com>")
|
|
|
|
.about("Does awesome things")
|
2018-10-19 20:42:13 +00:00
|
|
|
.arg("-c, --config=[FILE] 'Sets a custom config file'")
|
|
|
|
.arg("<output> 'Sets an optional output file'")
|
|
|
|
.arg("-d... 'Turn debugging information on'")
|
2018-01-25 04:05:05 +00:00
|
|
|
.subcommand(
|
2018-10-19 20:42:13 +00:00
|
|
|
App::new("test")
|
2018-01-25 04:05:05 +00:00
|
|
|
.about("does testing things")
|
2018-10-19 20:42:13 +00:00
|
|
|
.arg("-l, --list 'lists test values'"),
|
2018-01-25 04:05:05 +00:00
|
|
|
)
|
2016-04-10 00:35:24 +00:00
|
|
|
}
|