|
| 1 | +# [cliargs_derive][repo-url] [![crate.io][crateio-img]][crateio-url] [![doc.rs][docrs-img]][docrs-url] [![CI Status][ci-img]][ci-url] [![MIT License][mit-img]][mit-url] |
| 2 | + |
| 3 | +This derive macro is attached to a struct which holds command line option values, and automatically |
| 4 | +implements |
| 5 | +its method to generate `OptCfg`s from its fields, and other methods. |
| 6 | + |
| 7 | +This macro automatically implements the method to generates a vector of `OptCfg` from the field |
| 8 | +definitions and `opt` field attributes, and this also implements the method that instantiates |
| 9 | +the struct using the default values specified in `opt` field attributes, and implements the |
| 10 | +method to updates the field values with the values from the passed `HashMap`. |
| 11 | + |
| 12 | +The `opt` field attribute can have the following pairs of name and value: one is `cfg` to |
| 13 | +specify `names` and `defaults` of `OptCfg` struct, another is `desc` to specify `desc` of |
| 14 | +`OptCfg` struct, and yet another is `arg` to specify `arg_in_help` of `OptCfg` struct. |
| 15 | + |
| 16 | +The format of `cfg` is like `cfg="f,foo=123"`. |
| 17 | +The left side of the equal sign is the option name(s), and the right side is the default |
| 18 | +value(s). |
| 19 | +If there is no equal sign, it is determined that only the option name is specified. |
| 20 | +If you want to specify multiple option names, separate them with commas. |
| 21 | +If you want to specify multiple default values, separate them with commas and round them with |
| 22 | +square brackets, like `[1,2,3]`. |
| 23 | +If you want to use your favorite carachter as a separator, you can use it by putting it on the |
| 24 | +left side of the open square bracket, like `/[1/2/3]`. |
| 25 | + |
| 26 | +The following code is a sample of a option store struct. |
| 27 | + |
| 28 | +```rust |
| 29 | +extern crate cliargs_derive; |
| 30 | +use cliargs_derive::OptStore; |
| 31 | + |
| 32 | +#[derive(OptStore)] |
| 33 | +struct MyOptions { |
| 34 | + #[opt(cfg="f,foo-bar", desc="The description of foo-bar.")] |
| 35 | + foo_bar: bool, |
| 36 | + |
| 37 | + #[opt(cfg="b", desc="The description of baz.", arg="text")] |
| 38 | + baz: String, |
| 39 | + |
| 40 | + #[opt(cfg="q=[1,2,3]", desc="The description of qux.", arg="num...")] |
| 41 | + qux: Vec<u8>, |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +## License |
| 46 | + |
| 47 | +Copyright (C) 2024 Takayuki Sato |
| 48 | + |
| 49 | +This program is free software under MIT License.<br> |
| 50 | +See the file LICENSE in this distribution for more details. |
| 51 | + |
| 52 | + |
| 53 | +[repo-url]: https://github.com/sttk/cliargs-rust |
| 54 | +[crateio-img]: https://img.shields.io/badge/crate.io-ver.0.1.0-fc8d62?logo=rust |
| 55 | +[crateio-url]: https://crates.io/crates/cliargs_derive |
| 56 | +[docrs-img]: https://img.shields.io/badge/doc.rs-cliargs-66c2a5?logo=docs.rs |
| 57 | +[docrs-url]: https://docs.rs/cliargs_derive |
| 58 | +[ci-img]: https://github.com/sttk/cliargs-rust/actions/workflows/rust.yml/badge.svg?branch=main |
| 59 | +[ci-url]: https://github.com/sttk/cliargs-rust/actions |
| 60 | +[mit-img]: https://img.shields.io/badge/license-MIT-green.svg |
| 61 | +[mit-url]: https://opensource.org/licenses/MIT |
0 commit comments