config-easy 0.1.0

A small SQLite-backed interactive settings menu for command-line Rust applications
Documentation
  • Coverage
  • 77.78%
    14 out of 18 items documented1 out of 3 items with examples
  • Size
  • Source code size: 51.75 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 515.12 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • tw-libraries/rust/config-easy
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • T-Welsh

config-easy

Crates.io Documentation License Rust Edition

config-easy is a small Rust crate for displaying and editing key/value settings stored in a SQLite table.

It is intended for command-line applications that want a simple interactive configuration menu, usually shown when the application is run with a --config option.

Applications remain responsible for schema creation, default values, typed configuration structs, CLI parsing, and app-specific behavior.

Install

[dependencies]
config-easy = "0.1"
rusqlite = "0.32"

Default Schema

CREATE TABLE IF NOT EXISTS settings (
    key TEXT PRIMARY KEY,
    value TEXT NOT NULL
);

Basic Usage

let connection = rusqlite::Connection::open("app.db")?;

config_easy::run(&connection)?;

This uses:

  • table: settings
  • key column: key
  • value column: value
  • order by: key

Builder Usage

config_easy::builder(&connection)
    .table("settings")
    .key_column("key")
    .value_column("value")
    .order_by("key")
    .run()?;

Table and column names are validated as simple SQL identifiers before being interpolated into SQL. Values are always bound as SQL parameters.

Valid identifiers are non-empty, start with an ASCII letter or _, and contain only ASCII letters, numbers, and _.

Secret Values

config_easy::builder(&connection)
    .secret_keys(["my_api_key"])
    .run()?;

Non-empty secret values are displayed as ********. Empty secret values are displayed as empty. The underlying value is not changed unless the user selects that setting and enters a new value.

Validation

config_easy::builder(&connection)
    .validator(|key, value| {
        if key == "log_level" && !["debug", "info", "warn", "error"].contains(&value) {
            return Err(std::io::Error::new(
                std::io::ErrorKind::InvalidInput,
                "expected one of debug, info, warn, error",
            )
            .into());
        }

        Ok(())
    })
    .run()?;

Validation runs before a setting is updated.

Input values are trimmed before validation and saving.

Custom Actions

config_easy::builder(&connection)
    .action("r", "reset delta link", |conn| {
        conn.execute("DELETE FROM sync_state WHERE key = 'delta_link'", [])?;
        println!("Delta link reset.");
        Ok(())
    })
    .run()?;

Custom actions are displayed in the prompt and run when their key is selected. Action keys cannot be empty, numeric, duplicated, q, or quit.

Deliberately Not Included

  • Creating the settings table
  • Seeding default settings
  • Parsing values into app-specific types
  • CLI argument parsing
  • Encryption or secure secret storage
  • App-specific maintenance logic