toasty_cli/
config.rs

1use crate::migration::MigrationConfig;
2use anyhow::Result;
3use serde::{Deserialize, Serialize};
4use std::fs;
5use std::path::Path;
6
7/// Configuration for Toasty CLI operations
8#[derive(Debug, Default, Clone, Serialize, Deserialize)]
9pub struct Config {
10    /// Migration-related configuration
11    pub migration: MigrationConfig,
12}
13
14impl Config {
15    /// Create a new Config with default values
16    pub fn new() -> Self {
17        Self::default()
18    }
19
20    /// Load configuration from Toasty.toml in the project root
21    pub fn load() -> Result<Self> {
22        let path = Path::new("Toasty.toml");
23        let contents = fs::read_to_string(path)?;
24        let config: Config = toml::from_str(&contents)?;
25        Ok(config)
26    }
27
28    /// Set the migration configuration
29    pub fn migration(mut self, migration: MigrationConfig) -> Self {
30        self.migration = migration;
31        self
32    }
33}