diff --git a/src/main.rs b/src/main.rs index b34b994..b0806b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ mod mods; use toml; use serde; -use mods::{clearcache::clearcache, clone::clone, help::help, install::install, search::{a_search, r_search}, uninstall::uninstall, upgrade::upgrade, flatpak::flatpak}; +use mods::{clearcache::clearcache, clone::clone, help::help, install::install, search::{a_search, r_search}, uninstall::uninstall, upgrade::upgrade, flatpak::flatpak, snap::snap}; use std::{env, process::exit, process::Command}; #[derive(serde::Deserialize)] @@ -38,7 +38,7 @@ fn main() { [backends] pacman = true - flatpak = false + flatpak = true snap = false aur = true @@ -56,13 +56,27 @@ fn main() { let oper = &args[1]; if oper == "-S" { for arg in env::args().skip(2) { - let out = Command::new("pacman").arg("-Ss").arg(&arg).status().unwrap(); - if out.success() { - install(&arg); + if configfile.backends.pacman.unwrap() == true { + let out = Command::new("pacman").arg("-Ss").arg(&arg).status().unwrap(); + if out.success() { + install(&arg); + } else { + if configfile.backends.aur.unwrap() == true { + clone(&arg); + } else { + println!("ERROR: the package wasn't found in the repos and aur support is disabled"); + println!("Please enable aur support if you wish to check if this package exists in the aur"); + exit(1) + } + } + } else if configfile.backends.aur.unwrap() == true { + clone(&arg) } else { - clone(&arg); + println!("ERROR: it seems like neither pacman, nor aur support is enabled!"); + println!("Please enable either one of those option and try again"); + exit(1); } - } + } } else if oper == "-R" { for arg in env::args().skip(2) { uninstall(&arg); @@ -94,10 +108,29 @@ fn main() { } else { println!("ERROR: flatpak not found, please install flatpak and try again!"); println!("If you do have flatpak installed, please open an issue on the ame github repo!"); + exit(1); } } else { println!("ERROR: flatpak support is disabled in your ame config!"); println!("Enable flatpak support in your configuration and try again!"); + exit(1); + } + } else if oper == "-s" { + if configfile.backends.snap.unwrap() == true { + let b = std::path::Path::new("/usr/bin/snap").exists(); + if b == true { + for arg in env::args().skip(2) { + snap(&arg) + } + } else { + println!("ERROR: snap not found, please install snap and try again!"); + println!("If you do have snap installed, please open an issue on the ame github repo!"); + exit(1); + } + } else { + println!("ERROR: snap support is disabled in your ame config!"); + println!("Enable snap support in your configuration and try again!"); + exit(1); } } else { help(); diff --git a/src/mods.rs b/src/mods.rs index 65c173d..712113b 100644 --- a/src/mods.rs +++ b/src/mods.rs @@ -5,4 +5,5 @@ pub mod install; pub mod search; pub mod uninstall; pub mod upgrade; -pub mod flatpak; \ No newline at end of file +pub mod flatpak; +pub mod snap; \ No newline at end of file diff --git a/src/mods/snap.rs b/src/mods/snap.rs new file mode 100644 index 0000000..bf6b407 --- /dev/null +++ b/src/mods/snap.rs @@ -0,0 +1,6 @@ +use runas::Command; + +pub fn snap(pkg: &str) { + let errstr = format!("Oops.. Something went wrong!"); + Command::new("snap").arg("install").arg(&pkg).status().expect(&errstr); +} \ No newline at end of file