2020-02-04 08:10:53 +00:00
|
|
|
mod utils;
|
2016-10-26 18:35:20 +00:00
|
|
|
|
|
|
|
use std::str;
|
|
|
|
|
2018-11-14 17:05:06 +00:00
|
|
|
use clap::{App, AppSettings, Arg};
|
2016-10-26 18:35:20 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static NO_DERIVE_ORDER: &str = "test 1.2
|
2016-10-26 18:35:20 +00:00
|
|
|
|
2017-01-03 04:05:23 +00:00
|
|
|
USAGE:
|
|
|
|
test [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
--flag_a second flag
|
|
|
|
--flag_b first flag
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2017-01-03 04:05:23 +00:00
|
|
|
--option_a <option_a> second option
|
|
|
|
--option_b <option_b> first option
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2017-01-03 04:05:23 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static UNIFIED_HELP_AND_DERIVE: &str = "test 1.2
|
2017-01-03 04:05:23 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
--flag_b first flag
|
|
|
|
--option_b <option_b> first option
|
|
|
|
--flag_a second flag
|
2021-09-24 15:58:39 +00:00
|
|
|
--option_a <option_a> second option
|
2021-10-08 17:05:40 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2017-01-03 04:05:23 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static UNIFIED_DERIVE_SC_PROP: &str = "test-sub 1.2
|
2017-01-03 04:05:23 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test sub [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
--flag_b first flag
|
|
|
|
--option_b <option_b> first option
|
|
|
|
--flag_a second flag
|
|
|
|
--option_a <option_a> second option
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2017-01-03 04:05:23 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static UNIFIED_DERIVE_SC_PROP_EXPLICIT_ORDER: &str = "test-sub 1.2
|
2017-01-03 04:05:23 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test sub [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
--flag_a second flag
|
|
|
|
--flag_b first flag
|
|
|
|
--option_b <option_b> first option
|
|
|
|
--option_a <option_a> second option
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2016-10-26 18:35:20 +00:00
|
|
|
|
2021-02-07 11:58:43 +00:00
|
|
|
static PREFER_USER_HELP_DERIVE_ORDER: &str = "test 1.2
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
test [OPTIONS]
|
2021-02-07 11:58:43 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help message
|
2021-02-07 11:58:43 +00:00
|
|
|
--flag_b first flag
|
2021-09-24 15:58:39 +00:00
|
|
|
--flag_a second flag
|
2021-10-08 17:05:40 +00:00
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2021-02-07 11:58:43 +00:00
|
|
|
|
|
|
|
static PREFER_USER_HELP_SUBCMD_DERIVE_ORDER: &str = "test-sub 1.2
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
test sub [OPTIONS]
|
2021-02-07 11:58:43 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help message
|
2021-02-07 11:58:43 +00:00
|
|
|
--flag_b first flag
|
|
|
|
--flag_a second flag
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2021-02-07 11:58:43 +00:00
|
|
|
|
2016-10-26 18:35:20 +00:00
|
|
|
#[test]
|
|
|
|
fn no_derive_order() {
|
2018-01-25 04:05:05 +00:00
|
|
|
let app = App::new("test").version("1.2").args(&[
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("flag_b").long("flag_b").about("first flag"),
|
|
|
|
Arg::new("option_b")
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("option_b")
|
|
|
|
.takes_value(true)
|
2020-04-21 15:51:38 +00:00
|
|
|
.about("first option"),
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("flag_a").long("flag_a").about("second flag"),
|
|
|
|
Arg::new("option_a")
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("option_a")
|
|
|
|
.takes_value(true)
|
2020-04-21 15:51:38 +00:00
|
|
|
.about("second option"),
|
2018-01-25 04:05:05 +00:00
|
|
|
]);
|
|
|
|
|
2020-02-04 08:10:53 +00:00
|
|
|
assert!(utils::compare_output(
|
2018-01-25 04:05:05 +00:00
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
NO_DERIVE_ORDER,
|
|
|
|
false
|
|
|
|
));
|
2016-10-26 18:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn derive_order() {
|
|
|
|
let app = App::new("test")
|
|
|
|
.setting(AppSettings::DeriveDisplayOrder)
|
2017-01-03 04:05:23 +00:00
|
|
|
.version("1.2")
|
2016-10-26 18:35:20 +00:00
|
|
|
.args(&[
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("flag_b").long("flag_b").about("first flag"),
|
|
|
|
Arg::new("option_b")
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("option_b")
|
|
|
|
.takes_value(true)
|
2020-04-21 15:51:38 +00:00
|
|
|
.about("first option"),
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("flag_a").long("flag_a").about("second flag"),
|
|
|
|
Arg::new("option_a")
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("option_a")
|
|
|
|
.takes_value(true)
|
2020-04-21 15:51:38 +00:00
|
|
|
.about("second option"),
|
2016-10-26 18:35:20 +00:00
|
|
|
]);
|
|
|
|
|
2020-02-04 08:10:53 +00:00
|
|
|
assert!(utils::compare_output(
|
2018-01-25 04:05:05 +00:00
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
UNIFIED_HELP_AND_DERIVE,
|
|
|
|
false
|
|
|
|
));
|
2016-10-26 18:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn derive_order_subcommand_propagate() {
|
|
|
|
let app = App::new("test")
|
|
|
|
.global_setting(AppSettings::DeriveDisplayOrder)
|
2018-01-25 04:05:05 +00:00
|
|
|
.subcommand(
|
2018-10-19 20:42:13 +00:00
|
|
|
App::new("sub").version("1.2").args(&[
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("flag_b").long("flag_b").about("first flag"),
|
|
|
|
Arg::new("option_b")
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("option_b")
|
|
|
|
.takes_value(true)
|
2020-04-21 15:51:38 +00:00
|
|
|
.about("first option"),
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("flag_a").long("flag_a").about("second flag"),
|
|
|
|
Arg::new("option_a")
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("option_a")
|
|
|
|
.takes_value(true)
|
2020-04-21 15:51:38 +00:00
|
|
|
.about("second option"),
|
2018-01-25 04:05:05 +00:00
|
|
|
]),
|
|
|
|
);
|
|
|
|
|
2020-02-04 08:10:53 +00:00
|
|
|
assert!(utils::compare_output(
|
2018-01-25 04:05:05 +00:00
|
|
|
app,
|
|
|
|
"test sub --help",
|
|
|
|
UNIFIED_DERIVE_SC_PROP,
|
|
|
|
false
|
|
|
|
));
|
2016-10-26 18:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-10-11 22:01:33 +00:00
|
|
|
fn derive_order_subcommand_propagate_with_explicit_display_order() {
|
2016-10-26 18:35:20 +00:00
|
|
|
let app = App::new("test")
|
|
|
|
.global_setting(AppSettings::DeriveDisplayOrder)
|
2018-01-25 04:05:05 +00:00
|
|
|
.subcommand(
|
2018-10-19 20:42:13 +00:00
|
|
|
App::new("sub").version("1.2").args(&[
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("flag_b").long("flag_b").about("first flag"),
|
|
|
|
Arg::new("option_b")
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("option_b")
|
|
|
|
.takes_value(true)
|
2020-04-21 15:51:38 +00:00
|
|
|
.about("first option"),
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("flag_a")
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("flag_a")
|
2020-04-21 15:51:38 +00:00
|
|
|
.about("second flag")
|
2018-01-25 04:05:05 +00:00
|
|
|
.display_order(0),
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("option_a")
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("option_a")
|
|
|
|
.takes_value(true)
|
2020-04-21 15:51:38 +00:00
|
|
|
.about("second option"),
|
2018-01-25 04:05:05 +00:00
|
|
|
]),
|
|
|
|
);
|
|
|
|
|
2020-02-04 08:10:53 +00:00
|
|
|
assert!(utils::compare_output(
|
2018-01-25 04:05:05 +00:00
|
|
|
app,
|
|
|
|
"test sub --help",
|
|
|
|
UNIFIED_DERIVE_SC_PROP_EXPLICIT_ORDER,
|
|
|
|
false
|
|
|
|
));
|
2016-10-26 18:35:20 +00:00
|
|
|
}
|
2021-02-07 11:58:43 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn prefer_user_help_with_derive_order() {
|
|
|
|
let app = App::new("test")
|
|
|
|
.setting(AppSettings::DeriveDisplayOrder)
|
|
|
|
.version("1.2")
|
|
|
|
.args(&[
|
|
|
|
Arg::new("help")
|
|
|
|
.long("help")
|
|
|
|
.short('h')
|
2021-07-30 03:23:25 +00:00
|
|
|
.about("Print help message"),
|
2021-02-07 11:58:43 +00:00
|
|
|
Arg::new("flag_b").long("flag_b").about("first flag"),
|
|
|
|
Arg::new("flag_a").long("flag_a").about("second flag"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
assert!(utils::compare_output(
|
|
|
|
app,
|
|
|
|
"test --help",
|
|
|
|
PREFER_USER_HELP_DERIVE_ORDER,
|
|
|
|
false
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn prefer_user_help_in_subcommand_with_derive_order() {
|
|
|
|
let app = App::new("test")
|
|
|
|
.global_setting(AppSettings::DeriveDisplayOrder)
|
|
|
|
.subcommand(
|
|
|
|
App::new("sub").version("1.2").args(&[
|
|
|
|
Arg::new("help")
|
|
|
|
.long("help")
|
|
|
|
.short('h')
|
2021-07-30 03:23:25 +00:00
|
|
|
.about("Print help message"),
|
2021-02-07 11:58:43 +00:00
|
|
|
Arg::new("flag_b").long("flag_b").about("first flag"),
|
|
|
|
Arg::new("flag_a").long("flag_a").about("second flag"),
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(utils::compare_output(
|
|
|
|
app,
|
|
|
|
"test sub --help",
|
|
|
|
PREFER_USER_HELP_SUBCMD_DERIVE_ORDER,
|
|
|
|
false
|
|
|
|
));
|
|
|
|
}
|