#clap #cli #derive

bin+lib clapme

Parse command line arguments by defining a struct

16 releases

0.1.13 Aug 25, 2018
0.1.12 Aug 25, 2018
0.1.6 Jul 31, 2018
0.0.2 Jul 7, 2018

#61 in Command-line interface

Download history 5/week @ 2018-12-14 48/week @ 2018-12-21 2/week @ 2018-12-28 18/week @ 2019-01-04 5/week @ 2019-01-11 2/week @ 2019-01-18 2/week @ 2019-01-25 3/week @ 2019-02-01 1/week @ 2019-02-08 5/week @ 2019-02-22 34/week @ 2019-03-01 8/week @ 2019-03-08 19/week @ 2019-03-15 61/week @ 2019-03-22

152 downloads per month
Used in 2 crates

Apache-2.0/MIT

40KB
561 lines

ClapMe Build Status

Parse command line arguments by defining a struct. It combines clap with custom derive.

The basic idea is that you define a type that represents the information you want on the command-line from the person running your program, and derive(ClapMe) on that type, and then call YourType::from_args() to find out what your user gave you.

Relationship to clap

ClapMe uses clap to do the actual parsing of command-line flags. This is great, because clap does an awesome job at providing helpful features you wouldn't even have thought of if you wrote your own command-line processor. The biggest downside to using clap directly is that it does not nicely support translating its results into something you would want to use in your code, so there is a fair amount of repetitious calling of macros to do conversions into useful types.

Differences from structopt

StructOpt is a tool that serves the same function as clapme, but with a different philosophy. StructOpt strives to be as expressive as clap, and to enable all features clap does, and with a tightly coupled API. It does this by extensive use of attributes such as #[structopt(long = "long-name")], which define the behavior and property of each flag. This makes it powerful, but also rather verbose to use.

In contrast, ClapMe does not (yet?) support any attributes, and determines all behavior directly from your type. This means that you don't repeat yourself, but also means that you have less fine-grained control over your interface, and some interfaces may be well-nigh impossible.

You can implement the ClapMe trait manually, which does make it possible (and not even that painful) to create a different command-line for a given type, but this is not the intended way to use ClapMe.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2.5MB
~51K SLoC