refactor: cleans out deprecated code in prep for final beta.1 push

This commit is contained in:
Kevin K 2018-11-08 20:34:13 -05:00
parent 471376fdc7
commit 3550066c88
4 changed files with 34 additions and 30 deletions

View file

@ -334,7 +334,7 @@ subcommands:
Since this feature requires additional dependencies that not everyone may want, it is *not* compiled in by default and we need to enable a feature flag in Cargo.toml:
Simply change your `clap = "3.0.0-alpha.1"` to `clap = {version = "3.0.0-alpha.1", features = ["yaml"]}`.
Simply change your `clap = "3.0.0-beta.1"` to `clap = {version = "3.0.0-beta.1", features = ["yaml"]}`.
Finally we create our `main.rs` file just like we would have with the previous two examples:
@ -405,7 +405,7 @@ To test out `clap`'s default auto-generated help/version follow these steps:
```toml
[dependencies]
clap = "3.0.0-alpha.1"
clap = "3.0.0-beta.1"
```
* Add the following to your `src/main.rs`
@ -434,7 +434,7 @@ For full usage, add `clap` as a dependency in your `Cargo.toml` () to use from c
```toml
[dependencies]
clap = "~3.0.0-alpha.1"
clap = "~3.0.0-beta.1"
```
(**note**: If you are concerned with supporting a minimum version of Rust that is *older* than the current stable Rust minus 2 stable releases, it's recommended to use the `~major.minor.patch` style versions in your `Cargo.toml` which will only update the patch version automatically. For more information see the [Compatibility Policy](#compatibility-policy))
@ -458,7 +458,7 @@ To disable these, add this to your `Cargo.toml`:
```toml
[dependencies.clap]
version = "3.0.0-alpha.1"
version = "3.0.0-beta.1"
default-features = false
```
@ -466,7 +466,7 @@ You can also selectively enable only the features you'd like to include, by addi
```toml
[dependencies.clap]
version = "3.0.0-alpha.1"
version = "3.0.0-beta.1"
default-features = false
# Cherry-pick the features you'd like to use
@ -509,7 +509,7 @@ In order to keep from being surprised of breaking changes, it is **highly** reco
```toml
[dependencies]
clap = "~3.0.0-alpha.1"
clap = "~3.0.0-beta.1"
```
This will cause *only* the patch version to be updated upon a `cargo update` call, and therefore cannot break due to new features, or bumped minimum versions of Rust.
@ -526,11 +526,11 @@ Right now Cargo's version resolution is pretty naive, it's just a brute-force se
# In one Cargo.toml
[dependencies]
clap = "~3.0.0-alpha.1"
clap = "~3.0.0-beta.1"
# In another Cargo.toml
[dependencies]
clap = "3.0.0-alpha.1"
clap = "3.0.0-beta.1"
```
This is inherently an unresolvable crate graph in Cargo right now. Cargo requires there's only one major version of a crate, and being in the same workspace these two crates must share a version. This is impossible in this location, though, as these version constraints cannot be met.

View file

@ -804,11 +804,10 @@ impl<'a, 'b> App<'a, 'b> {
/// ```no_run
/// # use clap::{App, ArgGroup};
/// App::new("app")
/// .args_from_usage(
/// "--set-ver [ver] 'set the version manually'
/// --major 'auto increase major'
/// --minor 'auto increase minor'
/// --patch 'auto increase patch'")
/// .arg("--set-ver [ver] 'set the version manually'")
/// .arg("--major 'auto increase major'")
/// .arg("--minor 'auto increase minor'")
/// .arg("--patch 'auto increase patch'")
/// .group(ArgGroup::with_name("vers")
/// .args(&["set-ver", "major", "minor","patch"])
/// .required(true))
@ -827,13 +826,12 @@ impl<'a, 'b> App<'a, 'b> {
/// ```no_run
/// # use clap::{App, ArgGroup};
/// App::new("app")
/// .args_from_usage(
/// "--set-ver [ver] 'set the version manually'
/// --major 'auto increase major'
/// --minor 'auto increase minor'
/// --patch 'auto increase patch'
/// -c [FILE] 'a config file'
/// -i [IFACE] 'an interface'")
/// .arg("--set-ver [ver] 'set the version manually'")
/// .arg("--major 'auto increase major'")
/// .arg("--minor 'auto increase minor'")
/// .arg("--patch 'auto increase patch'")
/// .arg("-c [FILE] 'a config file'")
/// .arg("-i [IFACE] 'an interface'")
/// .groups(&[
/// ArgGroup::with_name("vers")
/// .args(&["set-ver", "major", "minor","patch"])
@ -1520,21 +1518,26 @@ impl<'a, 'b> App<'a, 'b> {
pub(crate) fn _create_help_and_version(&mut self) {
debugln!("App::_create_help_and_version;");
if !self.args.iter().any(|x| x.name == "help") {
if !(self.args.iter().any(|x| x.long == Some("help")) || self.args.iter().any(|x| x.name == "help")){
debugln!("App::_create_help_and_version: Building --help");
let help = Arg::with_name("help")
.short('h')
let mut help = Arg::with_name("help")
.long("help")
.help("Prints help information");
if !self.args.iter().any(|x| x.short == Some('h')) {
help = help.short('h');
}
self.args.push(help);
}
if !self.args.iter().any(|x| x.name == "version") {
if !(self.args.iter().any(|x| x.long == Some("version")) || self.args.iter().any(|x| x.name == "version") || self.is_set(AppSettings::DisableVersion)){
debugln!("App::_create_help_and_version: Building --version");
let version = Arg::with_name("version")
.short('V')
let mut version = Arg::with_name("version")
.long("version")
.help("Prints version information");
if !self.args.iter().any(|x| x.short == Some('V')) {
version = version.short('V');
}
self.args.push(version);
}
if self.has_subcommands()

View file

@ -516,7 +516,7 @@
//! [license]: https://raw.githubusercontent.com/kbknapp/clap-rs/master/LICENSE-MIT
#![crate_type = "lib"]
#![doc(html_root_url = "https://docs.rs/clap/3.0.0-alpha.1")]
#![doc(html_root_url = "https://docs.rs/clap/3.0.0-beta.1")]
#![deny(
missing_docs,
missing_debug_implementations,

View file

@ -3,7 +3,7 @@ extern crate regex;
use std::str;
use clap::{App, Arg, ErrorKind};
use clap::{App, Arg, ErrorKind, AppSettings};
include!("../clap-test.rs");
@ -47,12 +47,13 @@ fn complex_version_output() {
#[test]
fn override_ver() {
let m = App::new("test")
.setting(AppSettings::NoAutoVersion)
.author("Kevin K.")
.about("tests stuff")
.version("1.3")
.arg(Arg::from("-v, --version 'some version'"))
.mut_arg("version", |a| a.short('v').long("version").help("some version"))
.try_get_matches_from(vec!["test", "--version"]);
assert!(m.is_ok());
assert!(m.is_ok(), "{:?}", m.unwrap_err().kind);
assert!(m.unwrap().is_present("version"));
}