use crate::App;
use tsuki::{FromStr, Lua, Module, Ref, Table, fp};
mod capture;
mod copyfile;
mod copyfileas;
mod createdir;
mod removedir;
mod run;
mod spawn;
pub struct OsModule;
impl Module<App> for OsModule {
const NAME: &str = "os";
type Inst<'a> = Ref<'a, Table<App>>;
fn open(self, lua: &Lua<App>) -> Result<Self::Inst<'_>, Box<dyn core::error::Error>> {
lua.register_class::<self::spawn::Process>();
lua.register_class::<self::spawn::OutputStream>();
let m = lua.create_table();
let arch = lua.create_str(if cfg!(target_arch = "x86_64") {
"x86_64"
} else if cfg!(target_arch = "aarch64") {
"aarch64"
} else {
todo!()
});
m.set_str_key("arch", arch);
let kind = lua.create_str(if cfg!(target_os = "windows") {
"windows"
} else if cfg!(target_os = "macos") {
"macos"
} else if cfg!(target_os = "linux") {
"linux"
} else {
todo!()
});
m.set_str_key("kind", kind);
m.set_str_key("capture", fp!(self::capture::entry as async));
m.set_str_key("copyfile", fp!(self::copyfile::entry as async));
m.set_str_key("copyfileas", fp!(self::copyfileas::entry as async));
m.set_str_key("createdir", fp!(self::createdir::entry));
m.set_str_key("removedir", fp!(self::removedir::entry));
m.set_str_key("run", fp!(self::run::entry as async));
m.set_str_key("spawn", fp!(self::spawn::entry));
Ok(m)
}
}
#[derive(Default, FromStr)]
enum CopyMode {
#[default]
Content,
All,
}