#environment #account #settings #tktax #amazon #credit

tktax-config

Configuration handling for tktax, integrating environment- and file-based settings

1 unstable release

new 0.2.2 Feb 1, 2025

#4 in #tktax


Used in 7 crates (via tktax-account)

MIT license

70KB
632 lines

tktax-config

A Rust crate providing configuration logic for the tktax ecosystem. This crate merges file-based and environment-based settings into a centralized data structure, facilitating robust and extensible configuration management. The crate resolves potential conflicts with a predictable order, ensuring determinism in production environments (ἐν διατάξει).

Overview

tktax-config supplies:

  • GeneralConfig: Holds global flags, e.g., long for controlling operational modes.
  • AccountsConfig: Structures bank accounts, savings accounts, and credit accounts via nested HashMaps.
  • ProgramConfig: Aggregates sub-configurations and includes specialized logic for Amazon item mapping. Draws from local TOML files (e.g., config.toml) and environment variables prefixed with TKTAX.

Usage

  1. Add as a Dependency

    In your project’s Cargo.toml:

    [dependencies]
    tktax-config = { path = "../tktax-config" }
    

    (Adjust path or version as needed for your setup.)

  2. Instantiate the Config

    fn main() {
        // Leverage the `Default` trait to parse from `config.toml` 
        // and environment variables (`TKTAX_*`).
        let config = tktax_config::ProgramConfig::default();
    
        // Example usage
        if config.general().long() {
            println!("Long-mode enabled!");
        }
    
        if let Some(accounts) = config.accounts() {
            // Access checking, savings, credit, etc.
        }
    }
    
  3. Environment Variables and File Overrides

    • By default, config.toml is read from the current directory.
    • Environment variables such as TKTAX_GENERAL_LONG=false override file-based values.
    • Command-line options can be parsed (not shown here) to override defaults for ephemeral debugging.

Detailed Structures

ProgramConfig

  • general: GeneralConfig
    • Determines overarching behavior.
  • accounts: Option<AccountsConfig>
    • Houses checking, savings, and credit accounts.
  • amazon: Option<AmazonConfig>
    • Contains Amazon-related data for item mapping.

GeneralConfig

  • long: bool
    • Defaults to true. Indicates whether certain processes run in extended form.

AccountsConfig

  • checking: Option<HashMap<u32, String>>
    • Mapping of checking-account identifiers to descriptions.
  • savings: Option<HashMap<u32, String>>
    • Mapping of savings-account identifiers to descriptions.
  • credit: Option<HashMap<u32, String>>
    • Mapping of credit-account identifiers to descriptions.

AmazonConfig (From tktax_amazon)

  • Provided by the external tktax-amazon crate and integrated here.

Example config.toml

[general]
long = true

[accounts.checking]
101 = "Main Checking"
202 = "Secondary Checking"

[accounts.savings]
303 = "Emergency Fund"
404 = "Holiday Savings"

[accounts.credit]
505 = "Primary Credit Card"
606 = "Travel Rewards Card"

# Example Amazon config would reside under [amazon] depending on tktax_amazon definitions

Amazon-Specific Usage

  • create_amazon_item_map method in ProgramConfig will yield an AmazonItemMap, derived from data in [amazon]. If no Amazon data is present, it returns None.

Contributing

  1. Fork the repository.
  2. Create a feature branch.
  3. Commit your changes with clear messages.
  4. Open a Pull Request.

License

This project is licensed under the MIT License.


Happy configuring!

Dependencies

~26–38MB
~645K SLoC