sqawk 0.8.2

An SQL-based command-line tool for processing delimiter-separated files (CSV, TSV, etc.), inspired by awk
Documentation
//! Configuration module for sqawk
//!
//! This module provides a centralized configuration structure for the application.
//! It handles global settings that are passed down through the application rather
//! than using global state or passing individual settings.

/// Application configuration
///
/// This struct encapsulates all global configuration settings for the application.
/// It is created at startup and passed to components that need access to configuration.
/// This approach avoids global mutable state and makes dependencies explicit.
#[derive(Debug, Clone)]
pub struct AppConfig {
    /// Whether to show verbose output
    verbose: bool,

    /// Custom field separator for tables
    field_separator: Option<String>,

    /// Custom column definitions for tables
    /// Format: "table_name:col1,col2,..."
    table_definitions: Vec<String>,

    /// Whether to write changes back to files
    write_changes: bool,
}

impl AppConfig {
    /// Create a new application configuration
    ///
    /// # Arguments
    /// * `verbose` - Whether to show verbose output
    /// * `field_separator` - Optional field separator character/string from command line
    /// * `table_definitions` - Optional vector of table column definitions
    /// * `write_changes` - Whether to write changes back to files
    pub fn new(
        verbose: bool,
        field_separator: Option<String>,
        table_definitions: Vec<String>,
        write_changes: bool,
    ) -> Self {
        Self {
            verbose,
            field_separator,
            table_definitions,
            write_changes,
        }
    }

    /// Get the verbose flag
    pub fn verbose(&self) -> bool {
        self.verbose
    }

    /// Get the field separator
    pub fn field_separator(&self) -> Option<String> {
        self.field_separator.clone()
    }

    /// Get the table definitions
    pub fn table_definitions(&self) -> &[String] {
        &self.table_definitions
    }

    /// Get whether to write changes
    pub fn write_changes(&self) -> bool {
        self.write_changes
    }

    /// Set whether to write changes
    pub fn set_write_changes(&mut self, write: bool) {
        self.write_changes = write;
    }
}