1 unstable release
new 0.2.2 | Feb 1, 2025 |
---|
#4 in #tktax
Used in 7 crates
(via tktax-account)
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
HashMap
s. - 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 withTKTAX
.
Usage
-
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.) -
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. } }
-
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.
- By default,
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.
- Defaults to
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 inProgramConfig
will yield anAmazonItemMap
, derived from data in[amazon]
. If no Amazon data is present, it returnsNone
.
Contributing
- Fork the repository.
- Create a feature branch.
- Commit your changes with clear messages.
- Open a Pull Request.
License
This project is licensed under the MIT License.
Happy configuring!
Dependencies
~26–38MB
~645K SLoC