2016-04-10 00:35:24 +00:00
|
|
|
extern crate clap;
|
2017-01-03 04:05:23 +00:00
|
|
|
extern crate regex;
|
2016-04-10 00:35:24 +00:00
|
|
|
|
|
|
|
use clap::{App, SubCommand};
|
|
|
|
|
2017-01-03 04:05:23 +00:00
|
|
|
include!("../clap-test.rs");
|
|
|
|
|
2018-01-25 04:05:05 +00:00
|
|
|
static EXAMPLE1_TMPL_S: &'static str = include_str!("example1_tmpl_simple.txt");
|
|
|
|
static EXAMPLE1_TMPS_F: &'static str = include_str!("example1_tmpl_full.txt");
|
2016-04-10 00:35:24 +00:00
|
|
|
|
2016-05-30 09:39:54 +00:00
|
|
|
static CUSTOM_TEMPL_HELP: &'static str = "MyApp 1.0
|
|
|
|
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
|
|
|
|
-h, --help Prints help information
|
|
|
|
-V, --version Prints 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:
|
2017-01-03 04:05:23 +00:00
|
|
|
help Prints this message or the help of the given subcommand(s)
|
2016-05-30 09:39:54 +00:00
|
|
|
test does testing things";
|
|
|
|
|
|
|
|
static SIMPLE_TEMPLATE: &'static str = "MyApp 1.0
|
|
|
|
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
|
|
|
|
-h, --help Prints help information
|
|
|
|
-V, --version Prints version information
|
2016-05-30 09:39:54 +00:00
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-c, --config <FILE> Sets a custom config file
|
|
|
|
|
|
|
|
SUBCOMMANDS:
|
2017-01-03 04:05:23 +00:00
|
|
|
help Prints this message or the help of the given subcommand(s)
|
2016-05-30 09:39:54 +00:00
|
|
|
test does testing things";
|
|
|
|
|
2016-04-10 00:35:24 +00:00
|
|
|
#[test]
|
2016-05-30 09:39:54 +00:00
|
|
|
fn with_template() {
|
2017-01-03 04:05:23 +00:00
|
|
|
let app = app_example1().template(EXAMPLE1_TMPL_S);
|
2018-01-25 04:05:05 +00:00
|
|
|
assert!(test::compare_output(
|
|
|
|
app,
|
|
|
|
"MyApp --help",
|
|
|
|
SIMPLE_TEMPLATE,
|
|
|
|
false
|
|
|
|
));
|
2016-05-30 09:39:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn custom_template() {
|
|
|
|
let app = app_example1().template(EXAMPLE1_TMPS_F);
|
2018-01-25 04:05:05 +00:00
|
|
|
assert!(test::compare_output(
|
|
|
|
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")
|
|
|
|
.template("");
|
2017-01-03 04:05:23 +00:00
|
|
|
assert!(test::compare_output(app, "MyApp --help", "", 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")
|
|
|
|
.template("test no tag test");
|
|
|
|
assert!(test::compare_output(
|
|
|
|
app,
|
|
|
|
"MyApp --help",
|
|
|
|
"test no tag test",
|
|
|
|
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")
|
|
|
|
.template("test {unknown_tag} test");
|
|
|
|
assert!(test::compare_output(
|
|
|
|
app,
|
|
|
|
"MyApp --help",
|
|
|
|
"test {unknown_tag} test",
|
|
|
|
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")
|
|
|
|
.template("{author}\n{version}\n{about}\n{bin}");
|
|
|
|
assert!(test::compare_output(
|
|
|
|
app,
|
|
|
|
"MyApp --help",
|
|
|
|
"Kevin K. <kbknapp@gmail.com>\n1.0\nDoes awesome things\nMyApp",
|
|
|
|
false
|
|
|
|
));
|
2016-04-10 00:35:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-03 04:05:23 +00:00
|
|
|
// ----------
|
|
|
|
|
2016-04-10 00:35:24 +00:00
|
|
|
fn app_example1<'b, 'c>() -> App<'b, 'c> {
|
|
|
|
App::new("MyApp")
|
|
|
|
.version("1.0")
|
|
|
|
.author("Kevin K. <kbknapp@gmail.com>")
|
|
|
|
.about("Does awesome things")
|
2018-01-25 04:05:05 +00:00
|
|
|
.args_from_usage(
|
|
|
|
"-c, --config=[FILE] 'Sets a custom config file'
|
2016-05-30 09:39:54 +00:00
|
|
|
<output> 'Sets an optional output file'
|
2018-01-25 04:05:05 +00:00
|
|
|
-d... 'Turn debugging information on'",
|
|
|
|
)
|
|
|
|
.subcommand(
|
|
|
|
SubCommand::with_name("test")
|
|
|
|
.about("does testing things")
|
|
|
|
.arg_from_usage("-l, --list 'lists test values'"),
|
|
|
|
)
|
2016-04-10 00:35:24 +00:00
|
|
|
}
|