use super::collections::scripts::Scripts;
use crate::result::{Error, Result};
use settings_manager::prelude::{ListSetting, SystemSettings};
use std::path::Path;
use std::{fs, io};
use thot_core::system::Script;
use uuid::Uuid;
pub fn make_script(file: &Path) -> Result {
if !file.exists() {
return Err(io::Error::new(io::ErrorKind::NotFound, "script file does not exist").into());
}
if !file.is_file() {
return Err(
io::Error::new(io::ErrorKind::IsADirectory, "script file is not a file").into(),
);
}
let abs_path = match fs::canonicalize(file) {
Ok(path) => path,
Err(err) => return Err(err.into()),
};
let script = Script::new(abs_path);
let mut scripts = match Scripts::load() {
Ok(sets) => sets,
Err(err) => return Err(Error::SettingsError(err)),
};
scripts.push(script);
scripts.save()?;
Ok(())
}
pub fn r#move(id: Uuid, path: &Path) -> Result {
todo!();
}
pub fn script_by_path(path: &Path) -> Result<Script> {
todo!();
}
#[cfg(test)]
#[path = "./scripts_test.rs"]
mod scripts_test;