diff --git a/Cargo.toml b/Cargo.toml index 9e920118428..eebd2e74a94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,11 +13,14 @@ keywords = ["argument", "command", "arg", "parser", "parse"] license = "MIT" -[dependencies] -strsim = "*" - [features] -default=[] +default=["suggestions"] +suggestions=["strsim"] # for building with nightly and unstable features unstable=[] + +[dependencies.strsim] +version = "*" +optional = true + diff --git a/src/app.rs b/src/app.rs index 223c2365297..4f496edc93a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -11,12 +11,14 @@ use args::{ ArgMatches, Arg, SubCommand, MatchedArg}; use args::{ FlagBuilder, OptBuilder, PosBuilder}; use args::ArgGroup; +#[cfg(feature = "suggestions")] use strsim; /// Produces a string from a given list of possible values which is similar to /// the passed in value `v` with a certain confidence. /// Thus in a list of possible values like ["foo", "bar"], the value "fop" will yield /// `Some("foo")`, whereas "blark" would yield `None`. +#[cfg(feature = "suggestions")] fn did_you_mean<'a, T, I>(v: &str, possible_values: I) -> Option<&'a str> where T: AsRef + 'a, I: IntoIterator { @@ -35,6 +37,13 @@ fn did_you_mean<'a, T, I>(v: &str, possible_values: I) -> Option<&'a str> } } +#[cfg(not(feature = "suggestions"))] +fn did_you_mean<'a, T, I>(_: &str, _: I) -> Option<&'a str> + where T: AsRef + 'a, + I: IntoIterator { + None +} + /// A helper to determine message formatting enum DidYouMeanMessageStyle { /// Suggested value is a long flag diff --git a/src/lib.rs b/src/lib.rs index bf5f397ca63..f377736ceee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -348,6 +348,7 @@ //! - `Arg::new()` -> `Arg::with_name()` //! - `Arg::mutually_excludes()` -> `Arg::conflicts_with()` //! - `Arg::mutually_excludes_all()` -> `Arg::conflicts_with_all()` +#[cfg(feature = "suggestions")] extern crate strsim; pub use args::{Arg, SubCommand, ArgMatches, ArgGroup};