mint_cli/data/
mod.rs

1pub mod args;
2pub mod errors;
3mod excel;
4mod helpers;
5mod json;
6
7use crate::layout::value::{DataValue, ValueSource};
8use errors::DataError;
9use excel::ExcelDataSource;
10use json::JsonDataSource;
11
12/// Trait for data sources that provide values by name.
13pub trait DataSource: Sync {
14    /// Retrieves a single numeric or boolean value.
15    fn retrieve_single_value(&self, name: &str) -> Result<DataValue, DataError>;
16
17    /// Retrieves a 1D array (from sheet reference) or a literal string.
18    fn retrieve_1d_array_or_string(&self, name: &str) -> Result<ValueSource, DataError>;
19
20    /// Retrieves a 2D array from a sheet reference.
21    fn retrieve_2d_array(&self, name: &str) -> Result<Vec<Vec<DataValue>>, DataError>;
22}
23
24/// Creates a data source from CLI arguments.
25///
26/// Returns `None` if no data source is configured (e.g., no `--xlsx` provided).
27pub fn create_data_source(args: &args::DataArgs) -> Result<Option<Box<dyn DataSource>>, DataError> {
28    // Handle fallback from deprecated --variant flag
29    if args.variant.is_some() && args.version.is_none() {
30        eprintln!("Warning: --variant is deprecated, use --version instead");
31    }
32
33    match (&args.xlsx, &args.postgres, &args.rest, &args.json) {
34        (Some(_), _, _, _) => Ok(Some(Box::new(ExcelDataSource::new(args)?))),
35        (_, Some(_), _, _) => Ok(Some(Box::new(JsonDataSource::from_postgres(args)?))),
36        (_, _, Some(_), _) => Ok(Some(Box::new(JsonDataSource::from_rest(args)?))),
37        (_, _, _, Some(_)) => Ok(Some(Box::new(JsonDataSource::from_json(args)?))),
38        _ => Ok(None),
39    }
40}