added feature to print the current config using -Pc

i18n
axtlos 3 years ago
parent 9e565eaffd
commit 2106101a7f

@ -7,7 +7,7 @@ snap = false
aur = true aur = true
[pacman] [pacman]
noconfirm = true noconfirm = false
[aur] [aur]
clone_path = "/home/user/.cache/ame" clone_path = "/home/user/.cache/ame"

@ -1,10 +1,8 @@
mod mods; mod mods;
use toml; use toml;
use serde; use serde;
use std::fs::File; use mods::{clearcache::clearcache, clone::clone, help::help, install::install, search::{a_search, r_search}, uninstall::uninstall, upgrade::upgrade, flatpak::flatpak, snap::snap, config::printconfig};
use std::io::prelude::*; use std::{fs::File, io::prelude::*, env, process::exit, process::Command};
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)] #[derive(serde::Deserialize)]
struct General { struct General {
@ -37,7 +35,6 @@ fn main() {
let mut file = File::open("config.toml").expect("Unable to open the Config file"); let mut file = File::open("config.toml").expect("Unable to open the Config file");
let mut config = String::new(); let mut config = String::new();
file.read_to_string(&mut config).expect("Unable to read the Config file"); file.read_to_string(&mut config).expect("Unable to read the Config file");
println!("{}", config);
let configfile: General = toml::from_str(&config).unwrap(); let configfile: General = toml::from_str(&config).unwrap();
if args.len() <= 1 { if args.len() <= 1 {
@ -114,7 +111,7 @@ fn main() {
let b = std::path::Path::new("/usr/bin/snap").exists(); let b = std::path::Path::new("/usr/bin/snap").exists();
if b == true { if b == true {
for arg in env::args().skip(2) { for arg in env::args().skip(2) {
snap(&arg) snap(&arg);
} }
} else { } else {
println!("ERROR: snap not found, please install snap and try again!"); println!("ERROR: snap not found, please install snap and try again!");
@ -126,6 +123,8 @@ fn main() {
println!("Enable snap support in your configuration and try again!"); println!("Enable snap support in your configuration and try again!");
exit(1); exit(1);
} }
} else if oper == "-Pc" {
printconfig();
} else { } else {
help(); help();
exit(0); exit(0);

@ -6,4 +6,5 @@ pub mod search;
pub mod uninstall; pub mod uninstall;
pub mod upgrade; pub mod upgrade;
pub mod flatpak; pub mod flatpak;
pub mod snap; pub mod snap;
pub mod config;

@ -14,8 +14,8 @@ pub fn clone(pkg: &str) {
Repository::clone(&url, &path).unwrap(); Repository::clone(&url, &path).unwrap();
println!("Installing {} ...", pkg); println!("Installing {} ...", pkg);
Command::new("makepkg") Command::new("makepkg")
.current_dir(&cachedir) .current_dir(&cachedir)
.arg("-si") .arg("-si")
.status() .status()
.expect(&error); .expect(&error);
} }

@ -0,0 +1,55 @@
use toml;
use serde;
use std::{fs::File, io::prelude::*, env};
#[derive(serde::Deserialize)]
struct General {
cache: Option<String>,
backends: Backends,
pacman: Pacman,
aur: AUR,
}
#[derive(serde::Deserialize)]
struct Backends {
pacman: Option<bool>,
flatpak: Option<bool>,
snap: Option<bool>,
aur: Option<bool>,
}
#[derive(serde::Deserialize)]
struct Pacman {
noconfirm: Option<bool>,
}
#[derive(serde::Deserialize)]
struct AUR {
clone_path: Option<String>,
}
pub fn printconfig() {
let args: Vec<String> = env::args().collect();
let mut file = File::open("config.toml").expect("Unable to open the Config file");
let mut config = String::new();
file.read_to_string(&mut config).expect("Unable to read the Config file");
let configfile: General = toml::from_str(&config).unwrap();
println!("\
General:
Cache directory: {}
Backends:
pacman support: {}
aur support: {}
flatpak support: {}
snap support: {}
Pacman:
noconfirm: {}
aur:
Clone directory: {}", configfile.cache.unwrap(), configfile.backends.pacman.unwrap(), configfile.backends.aur.unwrap(), configfile.backends.flatpak.unwrap(), configfile.backends.snap.unwrap(), configfile.pacman.noconfirm.unwrap(), configfile.aur.clone_path.unwrap())
}

@ -3,8 +3,11 @@ pub fn help() {
Usage:\n Usage:\n
ame -S <pkg> - install a package ame -S <pkg> - install a package
ame -f <pkg> - install a package via flatpak ame -f <pkg> - install a package via flatpak
ame -s <pkg> - install a package via snap
ame -R <pkg> - remove a package ame -R <pkg> - remove a package
ame -Syu - system upgrade ame -Syu - system upgrade
ame -Ss <pkg> - search for a package ame -Ss <pkg> - search for a package
ame -Sa <pkg> - search for a package over the aur
ame -Sr <pkg> - search for a package over the repos
ame -Cc - clear package cache") ame -Cc - clear package cache")
} }
Loading…
Cancel
Save