refactor(Derives): changes the derive traits for the clap_derive crate

This commit is contained in:
Kevin K 2018-07-13 11:36:53 -04:00
parent 683105cdd1
commit 53b2ca51f4
No known key found for this signature in database
GPG key ID: 17218E4B3692F01A
2 changed files with 35 additions and 54 deletions

View file

@ -58,6 +58,7 @@ clippy = { version = "~0.0.166", optional = true }
atty = { version = "0.2.2", optional = true }
vec_map = { version = "0.8", optional = true }
term_size = { version = "1.0.0-beta1", optional = true }
clap_derive = { path = "../clap_derive", optional = true }
[target.'cfg(not(windows))'.dependencies]
ansi_term = { version = "0.11.0", optional = true }
@ -68,10 +69,11 @@ lazy_static = "1"
version-sync = "0.5"
[features]
default = ["suggestions", "color", "vec_map"]
default = ["suggestions", "color", "vec_map", "derive"]
suggestions = ["strsim"]
color = ["ansi_term", "atty"]
wrap_help = ["term_size", "textwrap/term_size"]
derive = ["clap_derive"]
yaml = ["yaml-rust"]
unstable = [] # for building with unstable clap features (doesn't require nightly Rust) (currently none)
nightly = [] # for building with unstable Rust features (currently none)

View file

@ -551,6 +551,10 @@ extern crate unicode_width;
extern crate vec_map;
#[cfg(feature = "yaml")]
extern crate yaml_rust;
#[cfg(feature = "derive")]
#[cfg_attr(feature = "derive", allow(unused_imports))]
#[cfg_attr(feature = "derive", macro_use)]
extern crate clap_derive;
#[cfg(feature = "yaml")]
pub use yaml_rust::YamlLoader;
@ -560,6 +564,12 @@ pub use output::fmt::Format;
pub use parse::errors::{Error, ErrorKind, Result};
pub use completions::Shell;
#[cfg(feature = "derive")]
#[cfg_attr(feature = "derive", doc(hidden))]
pub use clap_derive::*;
use std::result::Result as StdResult;
#[macro_use]
mod macros;
mod completions;
@ -572,58 +582,27 @@ const INTERNAL_ERROR_MSG: &'static str = "Fatal internal error. Please consider
report at https://github.com/kbknapp/clap-rs/issues";
const INVALID_UTF8: &'static str = "unexpected invalid UTF-8 code point";
#[cfg(unstable)]
pub use derive::{ArgEnum, ClapApp, FromArgMatches, IntoApp};
/// @TODO @release @docs
pub trait Clap: FromArgMatches + IntoApp + Sized {
#[cfg(unstable)]
mod derive {
/// @TODO @release @docs
pub trait Clap: IntoApp + FromArgMatches + Parse + Sized {}
/// @TODO @release @docs
pub trait Parse {
/// @TODO @release @docs
fn parse() -> Self { Self::from_argmatches(Self::into_app().get_matches()) }
/// @TODO @release @docs
fn parse_from<I, T>(argv: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
{
Self::from_argmatches(Self::into_app().get_matches_from(argv))
}
/// @TODO @release @docs
fn try_parse() -> Result<Self, clap::Error> {
Self::try_from_argmatches(Self::into_app().get_matches_safe()?)
}
/// @TODO @release @docs
fn try_parse_from<I, T>(argv: I) -> Result<Self, clap::Error>
where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
{
Self::try_from_argmatches(Self::into_app().get_matches_from_safe(argv)?)
}
}
/// @TODO @release @docs
pub trait IntoApp {
/// @TODO @release @docs
fn into_app<'a, 'b>() -> clap::App<'a, 'b>;
}
/// @TODO @release @docs
pub trait FromArgMatches: Sized {
/// @TODO @release @docs
fn from_argmatches<'a>(matches: clap::ArgMatches<'a>) -> Self;
/// @TODO @release @docs
fn try_from_argmatches<'a>(matches: clap::ArgMatches<'a>) -> Result<Self, clap::Error>;
}
/// @TODO @release @docs
pub trait ArgEnum {}
}
/// @TODO @release @docs
pub trait FromArgMatches: Sized {
/// @TODO @release @docs
fn from_argmatches<'a>(matches: &::parse::ArgMatches<'a>) -> Self;
/// @TODO @release @docs
fn try_from_argmatches<'a>(matches: &::parse::ArgMatches<'a>) -> StdResult<Self, ::parse::errors::Error> {
Ok(<Self as FromArgMatches>::from_argmatches(matches))
}
}
/// @TODO @release @docs
pub trait IntoApp: Sized {
/// @TODO @release @docs
fn into_app<'a, 'b>() -> ::build::App<'a, 'b>;
}
/// @TODO @release @docs
pub trait ArgEnum {}