Skip to content

Commit 37e1931

Browse files
authored
doc,comment: add LICENSE and README.md for cliargs_derive (#24)
1 parent 42a5b2c commit 37e1931

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

cliargs_derive/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Takayuki Sato
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

cliargs_derive/README.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)