PrefixOpt

Add command line options with a prefix to override fields of structs and enums with a derive macro. This is made to extend clap.

General use

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.

Example

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;

[macro_use]

extern crate prefixopt_derive; use prefixopt::core::*;

[derive(Debug, PrefixOpt)]

pub enum A { A(Box, Option>), B{x:T}, C, D(), E(::std::marker::PhantomData) } impl Default for A { fn default() -> A { A::A(Box::new(1), None) } }

fn main() { let aopt = A::::withprefix("o"); let app = aopt.asarguments().bindapp(clap::App::new("testing")); let a = aopt.matcharguments(&app.getmatches()); println!("{:?}", a); } ```

Why

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.

To do and possible extensions

In a general order of personal importance.

Changelog

License

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.