smart-config

Command-Line Extensions for smart-config

Build status License: MIT OR Apache-2.0 rust 1.91+ required

Docs: Docs.rs crate docs (main)

This library provides a couple of command-line extensions for the smart-config library:

Usage

Add this to your Crate.toml:

[dependencies]
smart-config-commands = "0.4.0-pre.3"

Printing help on config params

use std::io;
use smart_config::ConfigSchema;
use smart_config_commands::Printer;

let mut schema = ConfigSchema::default();
// Add configurations to the schema...

Printer::stdout().print_help(&schema, |param_ref| {
    // Allows filtering output params.
    param_ref.param.name.contains("test")
})?;
io::Result::Ok(())

Example output is as follows:

Example output for print_help

Generating Markdown reference docs

use std::io;
use smart_config::ConfigSchema;
use smart_config_commands::{MarkdownOptions, Printer};

let mut schema = ConfigSchema::default();
// Add configurations to the schema...

Printer::stdout().print_markdown_reference(&schema, &MarkdownOptions::default(), |_| true)?;
io::Result::Ok(())

For a binary exposing configuration utilities, prefer a command name based on the task, for example:

config docs > docs/src/setup/configuration.md

Debugging param values

use std::io;
use smart_config::{ConfigSchema, ConfigRepository};
use smart_config_commands::Printer;

let mut schema = ConfigSchema::default();
// Add configurations to the schema...
let mut repo = ConfigRepository::new(&schema);
// Add sources to the repo...

Printer::stdout().print_debug(&repo, |_| true)?;
io::Result::Ok(())

Example output is as follows:

Example output for print_debug

The output will contain deserialization errors for all available params:

Example output for print_debug

Outputting JSON / YAML

The library can fancy-print JSON and YAML. This be used together with smart-config tooling to produce default / example configs, diffs with default param values etc. See the example for a couple of use cases.

Example of fancy-printed YAML

License

Distributed under the terms of either

at your option.