From 2106101a7fa0010233b0f4141bcca1d895367782 Mon Sep 17 00:00:00 2001 From: axtlos <3alouchi2006@gmail.com> Date: Fri, 27 Aug 2021 20:31:00 +0200 Subject: [PATCH] added feature to print the current config using -Pc --- config.toml | 2 +- src/main.rs | 11 +++++----- src/mods.rs | 3 ++- src/mods/clone.rs | 8 +++---- src/mods/config.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++++ src/mods/help.rs | 3 +++ 6 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 src/mods/config.rs diff --git a/config.toml b/config.toml index eb302d4..9d5c0e8 100644 --- a/config.toml +++ b/config.toml @@ -7,7 +7,7 @@ snap = false aur = true [pacman] -noconfirm = true +noconfirm = false [aur] clone_path = "/home/user/.cache/ame" diff --git a/src/main.rs b/src/main.rs index 3276165..9e946fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,8 @@ mod mods; use toml; use serde; -use std::fs::File; -use std::io::prelude::*; -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}; +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::{fs::File, io::prelude::*, env, process::exit, process::Command}; #[derive(serde::Deserialize)] struct General { @@ -37,7 +35,6 @@ fn main() { 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"); - println!("{}", config); let configfile: General = toml::from_str(&config).unwrap(); if args.len() <= 1 { @@ -114,7 +111,7 @@ fn main() { let b = std::path::Path::new("/usr/bin/snap").exists(); if b == true { for arg in env::args().skip(2) { - snap(&arg) + snap(&arg); } } else { 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!"); exit(1); } + } else if oper == "-Pc" { + printconfig(); } else { help(); exit(0); diff --git a/src/mods.rs b/src/mods.rs index 712113b..aade6d0 100644 --- a/src/mods.rs +++ b/src/mods.rs @@ -6,4 +6,5 @@ pub mod search; pub mod uninstall; pub mod upgrade; pub mod flatpak; -pub mod snap; \ No newline at end of file +pub mod snap; +pub mod config; \ No newline at end of file diff --git a/src/mods/clone.rs b/src/mods/clone.rs index 9c904ea..d9ac3ba 100644 --- a/src/mods/clone.rs +++ b/src/mods/clone.rs @@ -14,8 +14,8 @@ pub fn clone(pkg: &str) { Repository::clone(&url, &path).unwrap(); println!("Installing {} ...", pkg); Command::new("makepkg") - .current_dir(&cachedir) - .arg("-si") - .status() - .expect(&error); + .current_dir(&cachedir) + .arg("-si") + .status() + .expect(&error); } diff --git a/src/mods/config.rs b/src/mods/config.rs new file mode 100644 index 0000000..625dae7 --- /dev/null +++ b/src/mods/config.rs @@ -0,0 +1,55 @@ +use toml; +use serde; +use std::{fs::File, io::prelude::*, env}; + + +#[derive(serde::Deserialize)] +struct General { + cache: Option, + backends: Backends, + pacman: Pacman, + aur: AUR, +} + +#[derive(serde::Deserialize)] +struct Backends { + pacman: Option, + flatpak: Option, + snap: Option, + aur: Option, +} + +#[derive(serde::Deserialize)] +struct Pacman { + noconfirm: Option, +} + +#[derive(serde::Deserialize)] +struct AUR { + clone_path: Option, +} + + + +pub fn printconfig() { + let args: Vec = 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()) +} \ No newline at end of file diff --git a/src/mods/help.rs b/src/mods/help.rs index 687dbbb..77e1342 100644 --- a/src/mods/help.rs +++ b/src/mods/help.rs @@ -3,8 +3,11 @@ pub fn help() { Usage:\n ame -S - install a package ame -f - install a package via flatpak +ame -s - install a package via snap ame -R - remove a package ame -Syu - system upgrade ame -Ss - search for a package +ame -Sa - search for a package over the aur +ame -Sr - search for a package over the repos ame -Cc - clear package cache") } \ No newline at end of file