rclap
rclap is a configuration helper based on clap. It is designed to expose the requirement as config files, environment variables, and command line arguments with the least amount of boilerplate code. Macro clap generator based on toml files
Usage
simple toml file
= { = "u16", = "8080", = "Server port number", = "PORT" }
= { = "localhost", = "connection URL", = "URL" }
Then the config struct can be used by the following code
use Parser;
use config;
;
The ip and port can be set by environment variables or command line arguments. The default values will be used if neither is set.
Arguments can be set by --ip and --port command line arguments and the following help message will be generated:
Usage: example [OPTIONS]
Options:
--"ip" <ip> connection URL [env: URL=] [default: localhost]
--"port" <port> Server port number [env: PORT=120] [default: 8080]
-h, --help Print help
The equivalent for the above code will be generated by the macro:
The example folder contains more working samples.
settings
| name | description |
|---|---|
| type | if not specified, String type will be used |
| env | the environment variable name to use |
| long | same as in clap if not specified the id value will be used instead |
| short | same as in clap |
| default | the default value to use if neither env nor command line argument is set |
| doc | the documentation string to use |
dependencies
rclap is macro generator based on clap and toml. the clap library is used to parse command line arguments and must be imported
= { = "4.5", = ["env", "derive"] }