Skip to content

Commit

Permalink
feat(did-you-mean): gate it behind 'suggestions'
Browse files Browse the repository at this point in the history
You can now disable the did-you-mean feature entirely, which also
removes the additional dependency it comes with.
Learn more about features and how to use them here:
http://doc.crates.io/manifest.html#the-[features]-section

Related to #103
  • Loading branch information
Byron authored and kbknapp committed May 5, 2015
1 parent de7d10a commit c0e3835
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

9 changes: 9 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<str> + 'a,
I: IntoIterator<Item=&'a T> {
Expand All @@ -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<str> + 'a,
I: IntoIterator<Item=&'a T> {
None
}

/// A helper to determine message formatting
enum DidYouMeanMessageStyle {
/// Suggested value is a long flag
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit c0e3835

Please sign in to comment.