use objets_metier_rs::errors::SageResult;
use objets_metier_rs::wrappers::cial::CialApplication;
const CIAL_CLSID: &str = "Objets100c.CIAL";
const DEFAULT_SAGE_USERNAME: &str = "<Administrateur>";
const DEFAULT_SAGE_PASSWORD: &str = "";
const DEFAULT_SAGE_DATABASE: &str = r"D:\TMP\BIJOU.MAE";
#[derive(Debug, Clone)]
pub struct SageTestConfig {
pub username: String,
pub password: String,
pub database: String,
}
impl SageTestConfig {
pub fn from_env() -> Self {
Self {
username: std::env::var("SAGE_USERNAME")
.unwrap_or_else(|_| DEFAULT_SAGE_USERNAME.to_string()),
password: std::env::var("SAGE_PASSWORD")
.unwrap_or_else(|_| DEFAULT_SAGE_PASSWORD.to_string()),
database: std::env::var("SAGE_DATABASE")
.unwrap_or_else(|_| DEFAULT_SAGE_DATABASE.to_string()),
}
}
}
pub fn connect_cial() -> SageResult<CialApplication> {
let config = SageTestConfig::from_env();
let cial = CialApplication::new(CIAL_CLSID)?;
cial.set_name(&config.database)?;
let loggable = cial.loggable()?;
loggable.set_user_name(&config.username)?;
loggable.set_user_pwd(&config.password)?;
cial.open()?;
Ok(cial)
}