#serde-derive #arguments-parser #config-parser #command-line-arguments #clap #config-file #settings

macro cli-settings-derive

Manage CLI settings with configuration file(s) and command line parsing, using serde and clap

8 releases

0.3.2 Oct 5, 2024
0.3.1 Oct 5, 2024
0.3.0 Oct 11, 2023
0.2.3 Sep 30, 2023
0.1.0 Sep 18, 2023

#610 in Command-line interface

Download history 6/week @ 2024-07-27 1/week @ 2024-09-21 289/week @ 2024-10-05 40/week @ 2024-10-12 3/week @ 2024-10-19 17/week @ 2024-11-02

72 downloads per month

MIT license

27KB
340 lines

cli-settings-derive

Crates.io docs.rs CI Crates.io

Use a derive macro with annotations on your Command Line Interface settings struct to manage the settings of your application:

  • create an instance with default values (provided by annotations)
  • read each possible configuration file, if it exists:
    • update the fields that are defined in the configuration file
  • parse the command line arguments, and update the relevant fields with the provided argument

By using annotations, each field can be configurable via the configuration file(s) and/or the command line.

cli-settings-derive can be seen as a top layer above

  • serde for the file configuration parsing
  • clap for the command line parsing

See doc.rs documentation for detailed documentation and an example.

See the crate repository for a complete working example, with:

  • clap settings to tune the generated help message (-h)
  • field with custom type and user provided function to parse the value from string

Dependencies

~4.5MB
~94K SLoC