diff --git a/Cargo.toml b/Cargo.toml index b9feb28..5213662 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,19 +1,55 @@ [package] name = "Amethyst" version = "3.0.0" -authors = [ "jnats ", "axtlos " ] +authors = [ "michal ", "axtlos " ] edition = "2021" -description = "A fast and efficient aur helper." +description = "A fast and efficient AUR helper." license-file = "LICENSE.md" [[bin]] name = "ame" path = "src/main.rs" +[features] +pkg-warner = [] + +[[bin]] +name = "apt" +path = "src/warn.rs" +required-features = [ "pkg-warner" ] + +[[bin]] +name = "apt-get" +path = "src/warn.rs" +required-features = [ "pkg-warner" ] + +[[bin]] +name = "dnf" +path = "src/warn.rs" +required-features = [ "pkg-warner" ] + +[[bin]] +name = "yum" +path = "src/warn.rs" +required-features = [ "pkg-warner" ] + +[[bin]] +name = "zypper" +path = "src/warn.rs" +required-features = [ "pkg-warner" ] + +[profile.release] +incremental = true +debug = true +lto = "fat" +codegen-units = 1 + [dependencies] -clap = { version = "2.34.0", default-features = false, features = [ "suggestions"] } -regex = { version = "1.5.4", default-features = false, features = [ "std" ] } +mimalloc = { version = "0.1.27", default-features = false } +clap = { version = "2.34.0", default-features = false, features = [ "suggestions" ] } +regex = { version = "1.5.4", default-features = false, features = [ "std", "unicode-perl" ] } runas = "0.2.1" rusqlite = { version = "0.26.3", default-features = false } reqwest = { version = "0.11.7", default-features = false, features = [ "blocking", "json", "default-tls" ] } -serde = { version = "1.0.90", default-features = false, features = [ "derive", "serde_derive" ] } \ No newline at end of file +serde = { version = "1.0.90", default-features = false, features = [ "derive", "serde_derive" ] } +throbber = { version = "0.1.4", default-features = false } \ No newline at end of file diff --git a/src/internal/mod.rs b/src/internal/mod.rs index ef0fcbd..d642b4a 100644 --- a/src/internal/mod.rs +++ b/src/internal/mod.rs @@ -4,6 +4,7 @@ mod clean; mod initialise; pub mod rpc; mod sort; +mod strings; pub mod structs; pub fn sort(a: &[String], options: Options) -> structs::Sorted { @@ -17,3 +18,11 @@ pub fn clean(a: &[String], options: Options) -> Vec { pub fn init(options: Options) { initialise::init(options); } + +pub fn info(a: String) { + strings::info(a); +} + +pub fn crash(a: String, b: i32) { + strings::crash(a, b); +} diff --git a/src/internal/strings.rs b/src/internal/strings.rs new file mode 100644 index 0000000..417dbe8 --- /dev/null +++ b/src/internal/strings.rs @@ -0,0 +1,10 @@ +use std::process::exit; + +pub fn info(a: String) { + println!("\x1b[2;22;35m❖\x1b[0m \x1b[1;37m{}\x1b[0m", a) +} + +pub fn crash(a: String, b: i32) { + println!("\x1b[2;22;31m❌\x1b[0m \x1b[1;91m{}\x1b[0m", a); + exit(b); +} diff --git a/src/main.rs b/src/main.rs index bab3f5e..b6a10ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,11 @@ +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + mod database; mod internal; mod operations; -use crate::internal::{init, sort, structs::Options}; +use crate::internal::{info, init, sort, structs::Options}; use clap::{App, AppSettings, Arg, ArgMatches, ArgSettings, Shell, SubCommand}; use std::io; use std::process::exit; @@ -137,6 +140,11 @@ fn main() { let packages = collect_matches(&matches); let sorted = sort(&packages, options); + info(format!( + "Attempting to install packages: {}", + packages.join(", ") + )); + if !sorted.repo.is_empty() { operations::install(sorted.repo, options); } @@ -154,11 +162,13 @@ fn main() { if let true = matches.is_present("remove") { let packages = collect_matches(&matches); + info(format!("Uninstalling packages: {}", &packages.join(", "))); operations::uninstall(packages, options); exit(0); } if let true = matches.is_present("upgrade") { + info("Performing system upgrade".to_string()); operations::upgrade(options); exit(0); } @@ -170,6 +180,7 @@ fn main() { .unwrap() .is_present("aur") { + info(format!("Searching AUR for {}", &packages[0])); operations::aur_search(&packages[0], options); } if matches @@ -177,6 +188,7 @@ fn main() { .unwrap() .is_present("repo") { + info(format!("Searching repos for {}", &packages[0])); operations::search(&packages[0], options); } @@ -189,6 +201,7 @@ fn main() { .unwrap() .is_present("aur") { + info(format!("Searching AUR and repos for {}", &packages[0])); operations::search(&packages[0], options); operations::aur_search(&packages[0], options); } diff --git a/src/operations/aur_install.rs b/src/operations/aur_install.rs index 4e7ad5c..c3bc172 100644 --- a/src/operations/aur_install.rs +++ b/src/operations/aur_install.rs @@ -1,10 +1,11 @@ +use crate::internal::crash; use crate::internal::rpc::rpcinfo; -use crate::Options; +use crate::{info, Options}; use std::env; use std::env::set_current_dir; use std::fs::remove_dir_all; use std::path::Path; -use std::process::Command; +use std::process::{Command, Stdio}; pub fn aur_install(a: Vec, options: Options) { let url = crate::internal::rpc::URL; @@ -25,6 +26,8 @@ pub fn aur_install(a: Vec, options: Options) { } } + info(format!("Installing packages {} from the AUR", a.join(", "))); + for package in a { let rpcres = rpcinfo(package); @@ -38,11 +41,13 @@ pub fn aur_install(a: Vec, options: Options) { eprintln!("Cloning {} into cachedir", pkg); } - // cloning + info("Cloning package source".to_string()); + set_current_dir(Path::new(&cachedir)).unwrap(); Command::new("git") .arg("clone") .arg(format!("{}/{}", url, pkg)) + .stdout(Stdio::null()) .status() .expect("Something has gone wrong"); @@ -59,10 +64,11 @@ pub fn aur_install(a: Vec, options: Options) { } // dep sorting + info("Sorting dependencies".to_string()); let sorted = crate::internal::sort(&rpcres.package.as_ref().unwrap().depends, options); if verbosity >= 1 { - eprintln!("Sorted depndencies for {} are:\n{:?}", pkg, &sorted) + eprintln!("Sorted dependencies for {} are:\n{:?}", pkg, &sorted) } let newopts = Options { @@ -91,6 +97,7 @@ pub fn aur_install(a: Vec, options: Options) { } // dep installing + info("Moving on to install dependencies".to_string()); crate::operations::install(sorted.repo, newopts); crate::operations::aur_install(sorted.aur, newopts); @@ -103,12 +110,20 @@ pub fn aur_install(a: Vec, options: Options) { } // package building and installing + info("Building time!".to_string()); set_current_dir(format!("{}/{}", cachedir, pkg)).unwrap(); - Command::new("makepkg") + let out = Command::new("makepkg") .args(&makepkg_args) .status() .expect("Something has gone wrong"); + if out.code() != Some(0) { + crash( + format!("Error encountered while installing {}, aborting", pkg), + 1, + ); + } + if makepkg_args.contains(&"--asdeps") { set_current_dir(&cachedir).unwrap(); remove_dir_all(format!("{}/{}", cachedir, pkg)).unwrap(); diff --git a/src/operations/install.rs b/src/operations/install.rs index 44bff47..0380ddc 100644 --- a/src/operations/install.rs +++ b/src/operations/install.rs @@ -1,6 +1,7 @@ -use crate::Options; +use crate::{info, Options}; pub fn install(mut a: Vec, options: Options) { + info(format!("Installing packages {} from repos", &a.join(", "))); let b = a.clone(); if options.noconfirm { a.push("--noconfirm".to_string()); @@ -28,7 +29,7 @@ pub fn install(mut a: Vec, options: Options) { .arg("--needed") .args(&a) .status() - .expect("Something has gone wrong."); + .expect("Something has gone wrong"); if let Some(x) = r.code() { if verbosity >= 1 { diff --git a/src/warn.rs b/src/warn.rs new file mode 100644 index 0000000..db60a1d --- /dev/null +++ b/src/warn.rs @@ -0,0 +1,14 @@ +use std::env; + +fn main() { + let arg = &env::args().collect::>()[0]; + + println!( + "Sorry for the bother, we don't use \x1b[2;22;35m{}\x1b[0m on Crystal, we use \x1b[2;22;35mame\x1b[0m! Please use that instead!", + arg.split('/') + .collect::>() + .last() + .unwrap() + ); + std::process::exit(0); +}