thot_local/system/
scripts.rs1use super::collections::scripts::Scripts;
3use crate::result::{Error, Result};
4use settings_manager::prelude::{ListSetting, SystemSettings};
5use std::path::Path;
6use std::{fs, io};
7use thot_core::system::Script;
8use uuid::Uuid;
9
10pub fn make_script(file: &Path) -> Result {
16 if !file.exists() {
17 return Err(io::Error::new(io::ErrorKind::NotFound, "script file does not exist").into());
18 }
19
20 if !file.is_file() {
21 return Err(
22 io::Error::new(io::ErrorKind::IsADirectory, "script file is not a file").into(),
23 );
24 }
25
26 let abs_path = match fs::canonicalize(file) {
27 Ok(path) => path,
28 Err(err) => return Err(err.into()),
29 };
30
31 let script = Script::new(abs_path);
32
33 let mut scripts = match Scripts::load() {
34 Ok(sets) => sets,
35 Err(err) => return Err(Error::SettingsError(err)),
36 };
37
38 scripts.push(script);
39 scripts.save()?;
40
41 Ok(())
43}
44
45pub fn r#move(id: Uuid, path: &Path) -> Result {
46 todo!();
47}
48
49pub fn script_by_path(path: &Path) -> Result<Script> {
51 todo!();
52}
53
54#[cfg(test)]
55#[path = "./scripts_test.rs"]
56mod scripts_test;