mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 06:12:40 +00:00
Remove version_about in favor of mut_arg
This commit is contained in:
parent
1bd902370a
commit
423e2dde00
4 changed files with 69 additions and 183 deletions
|
@ -25,7 +25,6 @@ TODO: `cargo`, `std` features
|
|||
* **Added Methods**
|
||||
* **App**
|
||||
* `App::help_about`
|
||||
* `App::version_about`
|
||||
* **Arg**
|
||||
* `Arg::hide_env`
|
||||
* **Added Settings**
|
||||
|
|
|
@ -74,7 +74,6 @@ pub struct App<'help> {
|
|||
pub(crate) about: Option<&'help str>,
|
||||
pub(crate) long_about: Option<&'help str>,
|
||||
pub(crate) help_about: Option<&'help str>,
|
||||
pub(crate) version_about: Option<&'help str>,
|
||||
pub(crate) before_help: Option<&'help str>,
|
||||
pub(crate) before_long_help: Option<&'help str>,
|
||||
pub(crate) after_help: Option<&'help str>,
|
||||
|
@ -519,27 +518,6 @@ impl<'help> App<'help> {
|
|||
self
|
||||
}
|
||||
|
||||
/// Sets the help text for the auto-generated version argument.
|
||||
///
|
||||
/// By default clap sets this to "Prints version information" 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")
|
||||
/// .version_about("Print version information") // Imperative tone
|
||||
/// # ;
|
||||
/// ```
|
||||
pub fn version_about<S: Into<&'help str>>(mut self, version_about: S) -> Self {
|
||||
self.version_about = Some(version_about.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// (Re)Sets the program's name. This will be displayed when displaying help
|
||||
/// or version messages.
|
||||
///
|
||||
|
@ -2433,9 +2411,6 @@ impl<'help> App<'help> {
|
|||
if $sc.help_about.is_none() && $_self.help_about.is_some() {
|
||||
$sc.help_about = $_self.help_about.clone();
|
||||
}
|
||||
if $sc.version_about.is_none() && $_self.version_about.is_some() {
|
||||
$sc.version_about = $_self.version_about.clone();
|
||||
}
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
@ -2525,10 +2500,6 @@ impl<'help> App<'help> {
|
|||
{
|
||||
version.short = Some('V');
|
||||
}
|
||||
|
||||
if self.version_about.is_some() {
|
||||
version.about = self.version_about;
|
||||
}
|
||||
}
|
||||
|
||||
if !self.is_set(AppSettings::DisableHelpSubcommand)
|
||||
|
|
152
tests/help.rs
152
tests/help.rs
|
@ -2244,158 +2244,6 @@ fn help_about_multi_subcmd_override_long_flag() {
|
|||
));
|
||||
}
|
||||
|
||||
static VERSION_ABOUT: &str = "myapp 1.0
|
||||
|
||||
USAGE:
|
||||
myapp
|
||||
|
||||
FLAGS:
|
||||
-h, --help Prints help information
|
||||
-V, --version Print custom version about text";
|
||||
|
||||
static VERSION_ABOUT_MULTI_SC: &str = "myapp-subcmd-multi 1.0
|
||||
|
||||
USAGE:
|
||||
myapp subcmd multi
|
||||
|
||||
FLAGS:
|
||||
-h, --help Prints help information
|
||||
-V, --version Print custom version about text";
|
||||
|
||||
static VERSION_ABOUT_MULTI_SC_OVERRIDE: &str = "myapp-subcmd-multi 1.0
|
||||
|
||||
USAGE:
|
||||
myapp subcmd multi
|
||||
|
||||
FLAGS:
|
||||
-h, --help Prints help information
|
||||
-V, --version Print custom version about text from multi";
|
||||
|
||||
#[test]
|
||||
fn version_about_short_flag() {
|
||||
let app = App::new("myapp")
|
||||
.version("1.0")
|
||||
.version_about("Print custom version about text");
|
||||
|
||||
assert!(utils::compare_output(app, "myapp -h", VERSION_ABOUT, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_about_long_flag() {
|
||||
let app = App::new("myapp")
|
||||
.version("1.0")
|
||||
.version_about("Print custom version about text");
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"myapp --help",
|
||||
VERSION_ABOUT,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_about_multi_subcmd() {
|
||||
let app = App::new("myapp")
|
||||
.version_about("Print custom version about text")
|
||||
.subcommand(App::new("subcmd").subcommand(App::new("multi").version("1.0")));
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"myapp help subcmd multi",
|
||||
VERSION_ABOUT_MULTI_SC,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_about_multi_subcmd_short_flag() {
|
||||
let app = App::new("myapp")
|
||||
.version_about("Print custom version about text")
|
||||
.subcommand(App::new("subcmd").subcommand(App::new("multi").version("1.0")));
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"myapp subcmd multi -h",
|
||||
VERSION_ABOUT_MULTI_SC,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_about_multi_subcmd_long_flag() {
|
||||
let app = App::new("myapp")
|
||||
.version_about("Print custom version about text")
|
||||
.subcommand(App::new("subcmd").subcommand(App::new("multi").version("1.0")));
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"myapp subcmd multi --help",
|
||||
VERSION_ABOUT_MULTI_SC,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_about_multi_subcmd_override() {
|
||||
let app = App::new("myapp")
|
||||
.version_about("Print custom version about text")
|
||||
.subcommand(
|
||||
App::new("subcmd").subcommand(
|
||||
App::new("multi")
|
||||
.version("1.0")
|
||||
.version_about("Print custom version about text from multi"),
|
||||
),
|
||||
);
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"myapp help subcmd multi",
|
||||
VERSION_ABOUT_MULTI_SC_OVERRIDE,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_about_multi_subcmd_override_short_flag() {
|
||||
let app = App::new("myapp")
|
||||
.version_about("Print custom version about text")
|
||||
.subcommand(
|
||||
App::new("subcmd").subcommand(
|
||||
App::new("multi")
|
||||
.version("1.0")
|
||||
.version_about("Print custom version about text from multi"),
|
||||
),
|
||||
);
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"myapp subcmd multi -h",
|
||||
VERSION_ABOUT_MULTI_SC_OVERRIDE,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_about_multi_subcmd_override_long_flag() {
|
||||
let app = App::new("myapp")
|
||||
.version_about("Print custom version about text")
|
||||
.subcommand(
|
||||
App::new("subcmd").subcommand(
|
||||
App::new("multi")
|
||||
.version("1.0")
|
||||
.version_about("Print custom version about text from multi"),
|
||||
),
|
||||
);
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"myapp subcmd multi --help",
|
||||
VERSION_ABOUT_MULTI_SC_OVERRIDE,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn option_usage_order() {
|
||||
let app = App::new("order").args(&[
|
||||
|
|
|
@ -192,9 +192,77 @@ fn override_version_about() {
|
|||
.mut_arg("version", |a| a.about("version info"));
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
app.clone(),
|
||||
"test -h",
|
||||
OVERRIDE_VERSION_ABOUT,
|
||||
false
|
||||
));
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"test --help",
|
||||
OVERRIDE_VERSION_ABOUT,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
static VERSION_ABOUT_MULTI_SC: &str = "myapp-subcmd-multi 1.0
|
||||
|
||||
USAGE:
|
||||
myapp subcmd multi
|
||||
|
||||
FLAGS:
|
||||
-h, --help Prints help information
|
||||
-V, --version Print custom version about text";
|
||||
|
||||
#[test]
|
||||
fn version_about_multi_subcmd() {
|
||||
let app = App::new("myapp")
|
||||
.mut_arg("version", |a| a.about("Print custom version about text"))
|
||||
.subcommand(App::new("subcmd").subcommand(App::new("multi").version("1.0")));
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app.clone(),
|
||||
"myapp help subcmd multi",
|
||||
VERSION_ABOUT_MULTI_SC,
|
||||
false
|
||||
));
|
||||
assert!(utils::compare_output(
|
||||
app.clone(),
|
||||
"myapp subcmd multi -h",
|
||||
VERSION_ABOUT_MULTI_SC,
|
||||
false
|
||||
));
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"myapp subcmd multi --help",
|
||||
VERSION_ABOUT_MULTI_SC,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
static VERSION_ABOUT_MULTI_SC_OVERRIDE: &str = "myapp-subcmd-multi 1.0
|
||||
|
||||
USAGE:
|
||||
myapp subcmd multi
|
||||
|
||||
FLAGS:
|
||||
-h, --help Prints help information
|
||||
-V, --version Print custom version about text from multi";
|
||||
|
||||
#[test]
|
||||
fn version_about_multi_subcmd_override() {
|
||||
let app = App::new("myapp")
|
||||
.mut_arg("version", |a| a.about("Print custom version about text"))
|
||||
.subcommand(App::new("subcmd").subcommand(
|
||||
App::new("multi").version("1.0").mut_arg("version", |a| {
|
||||
a.about("Print custom version about text from multi")
|
||||
}),
|
||||
));
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"myapp help subcmd multi",
|
||||
VERSION_ABOUT_MULTI_SC_OVERRIDE,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue