Macro clap::arg_enum

source ·
macro_rules! arg_enum {
    (enum $e:ident { $($v:ident),+ } ) => { ... };
    (pub enum $e:ident { $($v:ident),+ } ) => { ... };
    (#[derive($($d:ident),+)] enum $e:ident { $($v:ident),+ } ) => { ... };
    (#[derive($($d:ident),+)] pub enum $e:ident { $($v:ident),+ } ) => { ... };
}
Expand description

Convenience macro to generate more complete enums with variants to be used as a type when parsing arguments.

These enums support pub (or not) and use of the #[derive()] traits

§Example

arg_enum!{
	#[derive(Debug)]
	pub enum Foo {
		Bar,
		Baz,
		Qux
	}
}
// Foo enum can now be used via Foo::Bar, or Foo::Baz, etc
// and implements std::str::FromStr to use with the value_t! macros
fn main() {
	let m = App::new("app")
				.arg_from_usage("<foo> 'the foo'")
				.get_matches();
	let f = value_t_or_exit!(m.value_of("foo"), Foo);

	// Use f like any other Foo variant...
}