mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 07:12:32 +00:00
refactor(ArgEnum): comments out all ArgEnum functionality until functional
This commit is contained in:
parent
57c7d920ba
commit
2fad2c8ae4
5 changed files with 131 additions and 128 deletions
|
@ -1,7 +1,9 @@
|
|||
#[macro_use]
|
||||
extern crate clap;
|
||||
// #[macro_use]
|
||||
// extern crate clap;
|
||||
|
||||
use clap::{App, Arg};
|
||||
// use clap::{App, Arg};
|
||||
|
||||
fn main() {}
|
||||
|
||||
// #[derive(ArgEnum, Debug)]
|
||||
// enum ArgChoice {
|
||||
|
|
|
@ -1,27 +1,28 @@
|
|||
#[macro_use]
|
||||
extern crate clap;
|
||||
fn main() {}
|
||||
// #[macro_use]
|
||||
// extern crate clap;
|
||||
|
||||
use clap::{App, Arg};
|
||||
// use clap::{App, Arg};
|
||||
|
||||
#[derive(ArgEnum, Debug)]
|
||||
#[case_sensitive]
|
||||
enum ArgChoice {
|
||||
Foo,
|
||||
Bar,
|
||||
Baz,
|
||||
}
|
||||
// #[derive(ArgEnum, Debug)]
|
||||
// #[case_sensitive]
|
||||
// enum ArgChoice {
|
||||
// Foo,
|
||||
// Bar,
|
||||
// Baz,
|
||||
// }
|
||||
|
||||
fn main() {
|
||||
let matches = App::new(env!("CARGO_PKG_NAME"))
|
||||
.arg(
|
||||
Arg::with_name("arg")
|
||||
.required(true)
|
||||
.takes_value(true)
|
||||
.possible_values(&ArgChoice::variants()),
|
||||
)
|
||||
.get_matches();
|
||||
// fn main() {
|
||||
// let matches = App::new(env!("CARGO_PKG_NAME"))
|
||||
// .arg(
|
||||
// Arg::with_name("arg")
|
||||
// .required(true)
|
||||
// .takes_value(true)
|
||||
// .possible_values(&ArgChoice::variants()),
|
||||
// )
|
||||
// .get_matches();
|
||||
|
||||
let t = value_t!(matches.value_of("arg"), ArgChoice).unwrap_or_else(|e| e.exit());
|
||||
// let t = value_t!(matches.value_of("arg"), ArgChoice).unwrap_or_else(|e| e.exit());
|
||||
|
||||
println!("{:?}", t);
|
||||
}
|
||||
// println!("{:?}", t);
|
||||
// }
|
||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -25,12 +25,12 @@ extern crate proc_macro2;
|
|||
|
||||
mod derives;
|
||||
|
||||
/// It is required to have this seperate and specificly defined.
|
||||
#[proc_macro_derive(ArgEnum, attributes(case_sensitive))]
|
||||
pub fn arg_enum(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
let input: syn::DeriveInput = syn::parse(input).unwrap();
|
||||
derives::derive_arg_enum(&input).into()
|
||||
}
|
||||
// /// It is required to have this seperate and specificly defined.
|
||||
// #[proc_macro_derive(ArgEnum, attributes(case_sensitive))]
|
||||
// pub fn arg_enum(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
// let input: syn::DeriveInput = syn::parse(input).unwrap();
|
||||
// derives::derive_arg_enum(&input).into()
|
||||
// }
|
||||
|
||||
/// Generates the `Clap` impl.
|
||||
#[proc_macro_derive(Clap, attributes(clap))]
|
||||
|
|
|
@ -1,54 +1,54 @@
|
|||
// Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu>,
|
||||
// Kevin Knapp (@kbknapp) <kbknapp@gmail.com>, and
|
||||
// Andrew Hobden (@hoverbear) <andrew@hoverbear.org>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
#[macro_use]
|
||||
extern crate clap_derive;
|
||||
// // Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu>,
|
||||
// // Kevin Knapp (@kbknapp) <kbknapp@gmail.com>, and
|
||||
// // Andrew Hobden (@hoverbear) <andrew@hoverbear.org>
|
||||
// //
|
||||
// // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// // option. This file may not be copied, modified, or distributed
|
||||
// // except according to those terms.
|
||||
// #[macro_use]
|
||||
// extern crate clap;
|
||||
// #[macro_use]
|
||||
// extern crate clap_derive;
|
||||
|
||||
use clap::{App, Arg};
|
||||
// use clap::{App, Arg};
|
||||
|
||||
#[derive(ArgEnum, Debug, PartialEq)]
|
||||
enum ArgChoice {
|
||||
Foo,
|
||||
Bar,
|
||||
Baz,
|
||||
}
|
||||
// #[derive(ArgEnum, Debug, PartialEq)]
|
||||
// enum ArgChoice {
|
||||
// Foo,
|
||||
// Bar,
|
||||
// Baz,
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn when_lowercase() {
|
||||
let matches = App::new(env!("CARGO_PKG_NAME"))
|
||||
.arg(
|
||||
Arg::with_name("arg")
|
||||
.required(true)
|
||||
.takes_value(true)
|
||||
.possible_values(&ArgChoice::variants()),
|
||||
)
|
||||
.get_matches_from_safe(vec!["", "foo"])
|
||||
.unwrap();
|
||||
let t = value_t!(matches.value_of("arg"), ArgChoice);
|
||||
assert!(t.is_ok());
|
||||
assert_eq!(t.unwrap(), ArgChoice::Foo);
|
||||
}
|
||||
// #[test]
|
||||
// fn when_lowercase() {
|
||||
// let matches = App::new(env!("CARGO_PKG_NAME"))
|
||||
// .arg(
|
||||
// Arg::with_name("arg")
|
||||
// .required(true)
|
||||
// .takes_value(true)
|
||||
// .possible_values(&ArgChoice::variants()),
|
||||
// )
|
||||
// .get_matches_from_safe(vec!["", "foo"])
|
||||
// .unwrap();
|
||||
// let t = value_t!(matches.value_of("arg"), ArgChoice);
|
||||
// assert!(t.is_ok());
|
||||
// assert_eq!(t.unwrap(), ArgChoice::Foo);
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn when_capitalized() {
|
||||
let matches = App::new(env!("CARGO_PKG_NAME"))
|
||||
.arg(
|
||||
Arg::with_name("arg")
|
||||
.required(true)
|
||||
.takes_value(true)
|
||||
.possible_values(&ArgChoice::variants()),
|
||||
)
|
||||
.get_matches_from_safe(vec!["", "Foo"])
|
||||
.unwrap();
|
||||
let t = value_t!(matches.value_of("arg"), ArgChoice);
|
||||
assert!(t.is_ok());
|
||||
assert_eq!(t.unwrap(), ArgChoice::Foo);
|
||||
}
|
||||
// #[test]
|
||||
// fn when_capitalized() {
|
||||
// let matches = App::new(env!("CARGO_PKG_NAME"))
|
||||
// .arg(
|
||||
// Arg::with_name("arg")
|
||||
// .required(true)
|
||||
// .takes_value(true)
|
||||
// .possible_values(&ArgChoice::variants()),
|
||||
// )
|
||||
// .get_matches_from_safe(vec!["", "Foo"])
|
||||
// .unwrap();
|
||||
// let t = value_t!(matches.value_of("arg"), ArgChoice);
|
||||
// assert!(t.is_ok());
|
||||
// assert_eq!(t.unwrap(), ArgChoice::Foo);
|
||||
// }
|
||||
|
|
|
@ -1,51 +1,51 @@
|
|||
// Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu>,
|
||||
// Kevin Knapp (@kbknapp) <kbknapp@gmail.com>, and
|
||||
// Andrew Hobden (@hoverbear) <andrew@hoverbear.org>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
// // Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu>,
|
||||
// // Kevin Knapp (@kbknapp) <kbknapp@gmail.com>, and
|
||||
// // Andrew Hobden (@hoverbear) <andrew@hoverbear.org>
|
||||
// //
|
||||
// // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// // option. This file may not be copied, modified, or distributed
|
||||
// // except according to those terms.
|
||||
// #[macro_use]
|
||||
// extern crate clap;
|
||||
|
||||
use clap::{App, Arg, ArgEnum};
|
||||
// use clap::{App, Arg, ArgEnum};
|
||||
|
||||
#[derive(ArgEnum, Debug, PartialEq)]
|
||||
#[case_sensitive]
|
||||
enum ArgChoice {
|
||||
Foo,
|
||||
Bar,
|
||||
Baz,
|
||||
}
|
||||
// #[derive(ArgEnum, Debug, PartialEq)]
|
||||
// #[case_sensitive]
|
||||
// enum ArgChoice {
|
||||
// Foo,
|
||||
// Bar,
|
||||
// Baz,
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn when_lowercase() {
|
||||
let matches = App::new(env!("CARGO_PKG_NAME"))
|
||||
.arg(
|
||||
Arg::with_name("arg")
|
||||
.required(true)
|
||||
.takes_value(true)
|
||||
.possible_values(&ArgChoice::variants()),
|
||||
)
|
||||
.get_matches_from_safe(vec!["", "foo"]); // We expect this to fail.
|
||||
assert!(matches.is_err());
|
||||
assert_eq!(matches.unwrap_err().kind, clap::ErrorKind::InvalidValue);
|
||||
}
|
||||
// #[test]
|
||||
// fn when_lowercase() {
|
||||
// let matches = App::new(env!("CARGO_PKG_NAME"))
|
||||
// .arg(
|
||||
// Arg::with_name("arg")
|
||||
// .required(true)
|
||||
// .takes_value(true)
|
||||
// .possible_values(&ArgChoice::variants()),
|
||||
// )
|
||||
// .get_matches_from_safe(vec!["", "foo"]); // We expect this to fail.
|
||||
// assert!(matches.is_err());
|
||||
// assert_eq!(matches.unwrap_err().kind, clap::ErrorKind::InvalidValue);
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn when_capitalized() {
|
||||
let matches = App::new(env!("CARGO_PKG_NAME"))
|
||||
.arg(
|
||||
Arg::with_name("arg")
|
||||
.required(true)
|
||||
.takes_value(true)
|
||||
.possible_values(&ArgChoice::variants()),
|
||||
)
|
||||
.get_matches_from_safe(vec!["", "Foo"])
|
||||
.unwrap();
|
||||
let t = value_t!(matches.value_of("arg"), ArgChoice);
|
||||
assert!(t.is_ok());
|
||||
assert_eq!(t.unwrap(), ArgChoice::Foo);
|
||||
}
|
||||
// #[test]
|
||||
// fn when_capitalized() {
|
||||
// let matches = App::new(env!("CARGO_PKG_NAME"))
|
||||
// .arg(
|
||||
// Arg::with_name("arg")
|
||||
// .required(true)
|
||||
// .takes_value(true)
|
||||
// .possible_values(&ArgChoice::variants()),
|
||||
// )
|
||||
// .get_matches_from_safe(vec!["", "Foo"])
|
||||
// .unwrap();
|
||||
// let t = value_t!(matches.value_of("arg"), ArgChoice);
|
||||
// assert!(t.is_ok());
|
||||
// assert_eq!(t.unwrap(), ArgChoice::Foo);
|
||||
// }
|
||||
|
|
Loading…
Reference in a new issue