Skip to content

Playbooks for g

Story-style workflows—solo, team, and on-call. Jump into the full Use cases page anytime.

config

Configuration types and config-file I/O.

auto-generated This page is built from //! comments in the Rust source. Edit the source and run npm run docs:extract to update it.

Configuration types and config-file I/O.

Tutorial overview

This module defines the persistent configuration for the CLI, stored at ~/.config/g/config.toml. It uses serde and toml to map Rust structs directly to a human-readable file format, and provides helper functions for locating, loading, saving, and bootstrapping the config.

Rust concepts used here

  • #[derive(Serialize, Deserialize)] automatically generates TOML conversion code at compile time — no manual parsing needed.
  • HashMap<String, String> for dynamic key-value storage (git aliases).
  • The [Default] trait gives every config section a sensible baseline so users only need to override what they care about.
  • fs::create_dir_all and fs::write for managing the local filesystem.
  • anyhow::Context attaches a human-readable message to any Result error, making it much easier to diagnose file I/O failures.

Source: src/config/mod.rs