fixed some config issues, and changed the clone function to respect the config

i18n
Rafael Madriz 3 years ago
parent ce19ccf046
commit 5ed7c50a36

@ -1,4 +1,4 @@
cache = "/home/user/.cache/ame"
cache = "/home/ali/.ame"
[backends]
pacman = true
@ -10,4 +10,4 @@ aur = true
noconfirm = false
[aur]
clone_path = "/home/user/.cache/ame"
clone_path = "/home/ali/.ame"

@ -34,7 +34,6 @@ fn main() {
let args: Vec<String> = env::args().collect();
let mut confile = File::open("/etc/ame.toml").expect("Unable to open the Config file, did you delete ame.toml from /etc/??");
let mut config = String::new();
let conftostring = fs::read_to_string("/etc/ame.toml").expect("unable to open config file!");
let defaultconfig = format!(r#"
cache = "{}/.cache/ame"
@ -50,10 +49,11 @@ fn main() {
[aur]
clone_path = "{}/.cache/ame"
"#, std::env::var("HOME").unwrap(), std::env::var("HOME").unwrap());
let configfile: General = toml::from_str(&defaultconfig).unwrap();
if conftostring != "" {
let mut configfile: General = toml::from_str(&defaultconfig).unwrap();
if fs::read_to_string("/etc/ame.toml").expect("unable to open config file!") != "" {
confile.read_to_string(&mut config).expect("Unable to read the Config file");
let configfile: General = toml::from_str(&config).unwrap();
configfile = toml::from_str(&config).unwrap();
}
if args.len() <= 1 {
@ -61,6 +61,7 @@ fn main() {
exit(1);
}
let oper = &args[1];
let clone_path=configfile.aur.clone_path.unwrap();
if oper == "-S" || oper == "ins" || oper == "install" {
for arg in env::args().skip(2) {
if configfile.backends.pacman.unwrap() == true {
@ -70,7 +71,7 @@ fn main() {
install(configoption_noconfirm, &arg);
} else {
if configfile.backends.aur.unwrap() == true {
clone(&arg);
clone(&arg, &clone_path);
} 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");
@ -78,7 +79,7 @@ fn main() {
}
}
} else if configfile.backends.aur.unwrap() == true {
clone(&arg)
clone(&arg, &clone_path)
} else {
println!("ERROR: it seems like neither pacman, nor aur support is enabled!");
println!("Please enable either one of those option and try again");

@ -1,8 +1,8 @@
use git2::Repository;
use std::{fs, path::Path, process::Command};
pub fn clone(pkg: &str) {
let cachedir = format!("{}/.cache/ame/{}", std::env::var("HOME").unwrap(), pkg);
pub fn clone(pkg: &str, cachedir: &str) {
print!("{}", cachedir);
let error = format!("Couldn't install {}", &pkg);
let path = Path::new(&cachedir);
let results = raur::search(&pkg).expect(&error);

@ -1,6 +1,6 @@
use toml;
use serde;
use std::{fs, fs::File, io::prelude::*, env};
use std::{fs, fs::File, io::prelude::*};
#[derive(serde::Deserialize)]
@ -32,10 +32,8 @@ struct AUR {
pub fn printconfig() {
let args: Vec<String> = env::args().collect();
let mut confile = File::open("/etc/ame.toml").expect("Unable to open the Config file, did you delete ame.toml from /etc/??");
let mut config = String::new();
let conftostring = fs::read_to_string("/etc/ame.toml").expect("unable to open config file!");
let defaultconfig = format!(r#"
cache = "{}/.cache/ame"
@ -51,10 +49,10 @@ pub fn printconfig() {
[aur]
clone_path = "{}/.cache/ame"
"#, std::env::var("HOME").unwrap(), std::env::var("HOME").unwrap());
let configfile: General = toml::from_str(&defaultconfig).unwrap();
if conftostring != "" {
let mut configfile: General = toml::from_str(&defaultconfig).unwrap();
if fs::read_to_string("/etc/ame.toml").expect("unable to open config file!") != "" {
confile.read_to_string(&mut config).expect("Unable to read the Config file");
let configfile: General = toml::from_str(&config).unwrap();
configfile = toml::from_str(&config).unwrap();
}
println!("\
General:

@ -3,7 +3,7 @@ use runas::Command;
pub fn install(noconfirm: bool, pkg: &str) {
println!("{}",noconfirm);
let errstr = format!("Oops.. Something went wrong!");
if (noconfirm == false) {
if noconfirm == false {
Command::new("pacman").arg("-S").arg(&pkg).status().expect(&errstr);
} else {
Command::new("pacman").arg("-S").arg("--noconfirm").arg(&pkg).status().expect(&errstr);

@ -3,7 +3,7 @@ use runas::Command;
pub fn uninstall(noconfirm: bool, pkg: &str) {
let errstr = format!("Could not remove package {}", pkg);
if (noconfirm == false) {
if noconfirm == false {
Command::new("pacman").arg("-R").arg(&pkg).status().expect(&errstr);
} else {
Command::new("pacman").arg("-R").arg("--noconfirm").arg(&pkg).status().expect(&errstr);

@ -2,7 +2,7 @@ use runas::Command;
pub fn upgrade(noconfirm: bool) {
let errstr = format!("Something happened");
if (noconfirm == true) {
if noconfirm == true {
Command::new("pacman")
.arg("-Syu")
.arg("--noconfirm")

Loading…
Cancel
Save