mirror of
https://github.com/clap-rs/clap
synced 2024-09-21 06:41:54 +00:00
Remove help_about in favor of mut_arg
This commit is contained in:
parent
b824e0b088
commit
3758bba5e2
3 changed files with 13 additions and 125 deletions
|
@ -24,7 +24,6 @@ TODO: `cargo`, `std` features
|
||||||
|
|
||||||
* **Added Methods**
|
* **Added Methods**
|
||||||
* **App**
|
* **App**
|
||||||
* `App::help_about`
|
|
||||||
* **Arg**
|
* **Arg**
|
||||||
* `Arg::hide_env`
|
* `Arg::hide_env`
|
||||||
* **Added Settings**
|
* **Added Settings**
|
||||||
|
|
|
@ -73,7 +73,6 @@ pub struct App<'help> {
|
||||||
pub(crate) license: Option<&'help str>,
|
pub(crate) license: Option<&'help str>,
|
||||||
pub(crate) about: Option<&'help str>,
|
pub(crate) about: Option<&'help str>,
|
||||||
pub(crate) long_about: Option<&'help str>,
|
pub(crate) long_about: Option<&'help str>,
|
||||||
pub(crate) help_about: Option<&'help str>,
|
|
||||||
pub(crate) before_help: Option<&'help str>,
|
pub(crate) before_help: Option<&'help str>,
|
||||||
pub(crate) before_long_help: Option<&'help str>,
|
pub(crate) before_long_help: Option<&'help str>,
|
||||||
pub(crate) after_help: Option<&'help str>,
|
pub(crate) after_help: Option<&'help str>,
|
||||||
|
@ -495,29 +494,6 @@ impl<'help> App<'help> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the help text for the auto-generated help argument and subcommand.
|
|
||||||
///
|
|
||||||
/// By default clap sets this to "Prints help information" for the help
|
|
||||||
/// argument and "Prints this message or the help of the given subcommand(s)"
|
|
||||||
/// for the help subcommand but if you're using a different convention
|
|
||||||
/// for your help messages and would prefer a different phrasing you can
|
|
||||||
/// override it.
|
|
||||||
///
|
|
||||||
/// **NOTE:** This setting propagates to subcommands.
|
|
||||||
///
|
|
||||||
/// # Examples
|
|
||||||
///
|
|
||||||
/// ```no_run
|
|
||||||
/// # use clap::App;
|
|
||||||
/// App::new("myprog")
|
|
||||||
/// .help_about("Print help information") // Imperative tone
|
|
||||||
/// # ;
|
|
||||||
/// ```
|
|
||||||
pub fn help_about<S: Into<&'help str>>(mut self, help_about: S) -> Self {
|
|
||||||
self.help_about = Some(help_about.into());
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// (Re)Sets the program's name. This will be displayed when displaying help
|
/// (Re)Sets the program's name. This will be displayed when displaying help
|
||||||
/// or version messages.
|
/// or version messages.
|
||||||
///
|
///
|
||||||
|
@ -2423,9 +2399,6 @@ impl<'help> App<'help> {
|
||||||
$sc.g_settings = $sc.g_settings | $_self.g_settings;
|
$sc.g_settings = $sc.g_settings | $_self.g_settings;
|
||||||
$sc.term_w = $_self.term_w;
|
$sc.term_w = $_self.term_w;
|
||||||
$sc.max_w = $_self.max_w;
|
$sc.max_w = $_self.max_w;
|
||||||
if $sc.help_about.is_none() && $_self.help_about.is_some() {
|
|
||||||
$sc.help_about = $_self.help_about.clone();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
@ -2475,10 +2448,6 @@ impl<'help> App<'help> {
|
||||||
{
|
{
|
||||||
help.short = Some('h');
|
help.short = Some('h');
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.help_about.is_some() {
|
|
||||||
help.about = self.help_about;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.is_set(AppSettings::DisableVersionFlag)
|
if self.is_set(AppSettings::DisableVersionFlag)
|
||||||
|
@ -2523,10 +2492,8 @@ impl<'help> App<'help> {
|
||||||
{
|
{
|
||||||
debug!("App::_check_help_and_version: Building help subcommand");
|
debug!("App::_check_help_and_version: Building help subcommand");
|
||||||
self.subcommands.push(
|
self.subcommands.push(
|
||||||
App::new("help").about(
|
App::new("help")
|
||||||
self.help_about
|
.about("Prints this message or the help of the given subcommand(s)"),
|
||||||
.unwrap_or("Prints this message or the help of the given subcommand(s)"),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
100
tests/help.rs
100
tests/help.rs
|
@ -2092,15 +2092,6 @@ fn after_help_no_args() {
|
||||||
assert_eq!(help, AFTER_HELP_NO_ARGS);
|
assert_eq!(help, AFTER_HELP_NO_ARGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static HELP_ABOUT: &str = "myapp 1.0
|
|
||||||
|
|
||||||
USAGE:
|
|
||||||
myapp
|
|
||||||
|
|
||||||
FLAGS:
|
|
||||||
-h, --help Print custom help about text
|
|
||||||
-V, --version Prints version information";
|
|
||||||
|
|
||||||
static HELP_ABOUT_MULTI_SC: &str = "myapp-subcmd-multi 1.0
|
static HELP_ABOUT_MULTI_SC: &str = "myapp-subcmd-multi 1.0
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
|
@ -2119,63 +2110,24 @@ FLAGS:
|
||||||
-h, --help Print custom help about text from multi
|
-h, --help Print custom help about text from multi
|
||||||
-V, --version Prints version information";
|
-V, --version Prints version information";
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn help_about_short_flag() {
|
|
||||||
let app = App::new("myapp")
|
|
||||||
.version("1.0")
|
|
||||||
.help_about("Print custom help about text");
|
|
||||||
|
|
||||||
assert!(utils::compare_output(app, "myapp -h", HELP_ABOUT, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn help_about_long_flag() {
|
|
||||||
let app = App::new("myapp")
|
|
||||||
.version("1.0")
|
|
||||||
.help_about("Print custom help about text");
|
|
||||||
|
|
||||||
assert!(utils::compare_output(
|
|
||||||
app,
|
|
||||||
"myapp --help",
|
|
||||||
HELP_ABOUT,
|
|
||||||
false
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn help_about_multi_subcmd() {
|
fn help_about_multi_subcmd() {
|
||||||
let app = App::new("myapp")
|
let app = App::new("myapp")
|
||||||
.help_about("Print custom help about text")
|
.mut_arg("help", |h| h.about("Print custom help about text"))
|
||||||
.subcommand(App::new("subcmd").subcommand(App::new("multi").version("1.0")));
|
.subcommand(App::new("subcmd").subcommand(App::new("multi").version("1.0")));
|
||||||
|
|
||||||
assert!(utils::compare_output(
|
assert!(utils::compare_output(
|
||||||
app,
|
app.clone(),
|
||||||
"myapp help subcmd multi",
|
"myapp help subcmd multi",
|
||||||
HELP_ABOUT_MULTI_SC,
|
HELP_ABOUT_MULTI_SC,
|
||||||
false
|
false
|
||||||
));
|
));
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn help_about_multi_subcmd_short_flag() {
|
|
||||||
let app = App::new("myapp")
|
|
||||||
.help_about("Print custom help about text")
|
|
||||||
.subcommand(App::new("subcmd").subcommand(App::new("multi").version("1.0")));
|
|
||||||
|
|
||||||
assert!(utils::compare_output(
|
assert!(utils::compare_output(
|
||||||
app,
|
app.clone(),
|
||||||
"myapp subcmd multi -h",
|
"myapp subcmd multi -h",
|
||||||
HELP_ABOUT_MULTI_SC,
|
HELP_ABOUT_MULTI_SC,
|
||||||
false
|
false
|
||||||
));
|
));
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn help_about_multi_subcmd_long_flag() {
|
|
||||||
let app = App::new("myapp")
|
|
||||||
.help_about("Print custom help about text")
|
|
||||||
.subcommand(App::new("subcmd").subcommand(App::new("multi").version("1.0")));
|
|
||||||
|
|
||||||
assert!(utils::compare_output(
|
assert!(utils::compare_output(
|
||||||
app,
|
app,
|
||||||
"myapp subcmd multi --help",
|
"myapp subcmd multi --help",
|
||||||
|
@ -2187,55 +2139,25 @@ fn help_about_multi_subcmd_long_flag() {
|
||||||
#[test]
|
#[test]
|
||||||
fn help_about_multi_subcmd_override() {
|
fn help_about_multi_subcmd_override() {
|
||||||
let app = App::new("myapp")
|
let app = App::new("myapp")
|
||||||
.help_about("Print custom help about text")
|
.mut_arg("help", |h| h.about("Print custom help about text"))
|
||||||
.subcommand(
|
.subcommand(App::new("subcmd").subcommand(
|
||||||
App::new("subcmd").subcommand(
|
App::new("multi").version("1.0").mut_arg("help", |h| {
|
||||||
App::new("multi")
|
h.about("Print custom help about text from multi")
|
||||||
.version("1.0")
|
}),
|
||||||
.help_about("Print custom help about text from multi"),
|
));
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(utils::compare_output(
|
assert!(utils::compare_output(
|
||||||
app,
|
app.clone(),
|
||||||
"myapp help subcmd multi",
|
"myapp help subcmd multi",
|
||||||
HELP_ABOUT_MULTI_SC_OVERRIDE,
|
HELP_ABOUT_MULTI_SC_OVERRIDE,
|
||||||
false
|
false
|
||||||
));
|
));
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn help_about_multi_subcmd_override_short_flag() {
|
|
||||||
let app = App::new("myapp")
|
|
||||||
.help_about("Print custom help about text")
|
|
||||||
.subcommand(
|
|
||||||
App::new("subcmd").subcommand(
|
|
||||||
App::new("multi")
|
|
||||||
.version("1.0")
|
|
||||||
.help_about("Print custom help about text from multi"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(utils::compare_output(
|
assert!(utils::compare_output(
|
||||||
app,
|
app.clone(),
|
||||||
"myapp subcmd multi -h",
|
"myapp subcmd multi -h",
|
||||||
HELP_ABOUT_MULTI_SC_OVERRIDE,
|
HELP_ABOUT_MULTI_SC_OVERRIDE,
|
||||||
false
|
false
|
||||||
));
|
));
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn help_about_multi_subcmd_override_long_flag() {
|
|
||||||
let app = App::new("myapp")
|
|
||||||
.help_about("Print custom help about text")
|
|
||||||
.subcommand(
|
|
||||||
App::new("subcmd").subcommand(
|
|
||||||
App::new("multi")
|
|
||||||
.version("1.0")
|
|
||||||
.help_about("Print custom help about text from multi"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(utils::compare_output(
|
assert!(utils::compare_output(
|
||||||
app,
|
app,
|
||||||
"myapp subcmd multi --help",
|
"myapp subcmd multi --help",
|
||||||
|
|
Loading…
Reference in a new issue