Add command line options with a prefix to override fields of structs and enums with a derive macro. This is made to extend clap.
Deriving PrefixOpt for a struct or enum implements the PrefixOpt trait for the struct which allows to create a struct with a prefix. This struct can be transformed into arguments and bound to a clap::App
. The struct allows parsing the ArgMatches
of the App
.
Derivator of PrefixOpt requires that both structs and enums implement Default
.
Add prefixopt
and prefixopt-derive
to your dependencies of your Cargo.toml
:
toml
[dependencies]
prefixopt = "0.1.0"
prefixopt-derive = "0.1.0"
And then, in your rust file: ```rust extern crate prefixopt;
extern crate prefixopt_derive; use prefixopt::core::*;
pub enum A {
A(Box
pub enum B { Foo, Bar, Bux, } impl Default for A { fn default() -> A { A::A(Box::new(1), None) } } impl Default for B { fn default() -> B { B::Foo } }
fn main() { let splitc = A::withprefix("o"); let args = splitc.asarguments(); let app = args.bindapp(clap::App::new("testing")); let matches = app.getmatches(); let split = splitc.match_arguments(&matches); println!("{:?}", split); } ```
I have a program with too much options to encode manually. I liked OpenSSH's approach with -o
which is hopefully automatically generated. I extended the approach to enums and liked the index-like syntax.
In a general order of personal importance.
Dual-licensed.
Licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 or the MIT license http://opensource.org/licenses/MIT, at your option. This project may not be copied, modified, or distributed except according to those terms.