#cli-config #boilerplate #clap #logging #setup

clappconfig

Clap-based app config boilerplate: set up logging, load config, parse args

5 releases (3 breaking)

0.4.0 May 10, 2020
0.3.1 May 7, 2020
0.3.0 May 7, 2020
0.2.0 Apr 24, 2020
0.1.0 Apr 20, 2020

#898 in Command-line interface

Download history 14/week @ 2023-11-20 6/week @ 2023-11-27 29/week @ 2023-12-04 17/week @ 2023-12-11 17/week @ 2024-01-01 49/week @ 2024-01-08 16/week @ 2024-01-15 5/week @ 2024-01-22 10/week @ 2024-01-29 20/week @ 2024-02-12 75/week @ 2024-02-19 54/week @ 2024-02-26 54/week @ 2024-03-04

203 downloads per month

MIT license

12KB
179 lines

clappconfig - CLI app config boilerplate

Clap
  App
     Config
-----------
clappconfig

This crate provides a simple CLI app boilerplate that takes care of the most repetitive init tasks:

  • Load JSON5 config from a custom or default path (or use Default::default())
  • Set up logging, with CLI and config-based overrides
  • Optionally print the loaded or default config
  • Show help / version on demand, courtesy of clap
  • Optional start-up banner print

Supports custom clap arguments as well.

-> The repository is open to improvement PRs.

Logging

  • uses env_logger by default
  • level can be set in the config file
  • log level can be overridden by the --log CLI flag
  • log level can be increased by repeated use of -v or --verbose

Re-exports

The crates re-exports crates used in public API: clap, anyhow, log.

Example

See the examples directory.

The example called "rotn" implements rot13 as a command-line tool.

$ cargo run --example rotn -- -h

Rot-N 0.1.0 by Ondřej Hruška <ondra@ondrovo.com>

USAGE:
    rotn [FLAGS] [OPTIONS] --input <FILE>

FLAGS:
        --default-config    Print the default config JSON for reference (or to be piped to a file)
        --dump-config       Print the loaded config struct
    -h, --help              Prints help information
    -V, --version           Prints version information
    -v, --verbose           Increase logging verbosity (repeat to increase)

OPTIONS:
    -c, --config <FILE>    Sets a custom config file (JSON5)
    -i, --input <FILE>     Input file
        --log <LEVEL>      Set logging verbosity (error,warning,info,debug,trace)
    -n, --shift <N>        Positive or negative shift, default 13

To get rot13 of this README, run cargo run --example rotn -- -iREADME.md.

Dependencies

~5.5–8MB
~144K SLoC