lots of stuff

i18n
michal 2 years ago
parent 284a0bd21c
commit 62a9b40d48

@ -2,7 +2,7 @@
name = "ame"
version = "3.0.0"
authors = [ "jnats <michal@tar.black>", "axtlos <axtlos@tar.black>" ]
edition = "2018"
edition = "2021"
description = "A fast and efficient aur helper."
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -10,5 +10,6 @@ description = "A fast and efficient aur helper."
[dependencies]
clap = "2.34.0"
regex = "1.5.4"
runas = "0.2.1"
reqwest = { version = "0.11.7", default-features = false, features = [ "blocking", "json", "default-tls" ] }
serde = { version = "1.0.90", default-features = false, features = [ "derive" ] }
serde = { version = "1.0.90", default-features = false, features = [ "derive", "serde_derive" ] }

@ -1,9 +1,10 @@
use crate::Options;
use regex::Regex;
pub fn clean(a: &[String], verbosity: i32) -> Vec<String> {
pub fn clean(a: &[String], options: Options) -> Vec<String> {
let r = Regex::new(r"(\S+)((?:>=|<=|>|<)\S+$)").unwrap();
let mut cleaned: Vec<String> = vec![];
let verbosity = options.verbosity;
for b in a {
if r.captures_iter(b).count() > 0 {

@ -1,12 +1,14 @@
use crate::Options;
mod clean;
pub mod rpc;
mod sort;
pub mod structs;
pub fn sort(a: &[String], verbosity: i32) -> structs::Sorted {
sort::sort(a, verbosity)
pub fn sort(a: &[String], options: Options) -> structs::Sorted {
sort::sort(a, options)
}
pub fn clean(a: &[String], verbosity: i32) -> Vec<String> {
clean::clean(a, verbosity)
pub fn clean(a: &[String], options: Options) -> Vec<String> {
clean::clean(a, options)
}

@ -1,13 +1,14 @@
use crate::internal::{clean, rpc, structs};
use crate::Options;
use std::process::{Command, Stdio};
pub fn sort(input: &[String], verbosity: i32) -> structs::Sorted {
#[allow(unused_mut)]
pub fn sort(input: &[String], options: Options) -> structs::Sorted {
let mut repo: Vec<String> = vec![];
let mut aur: Vec<String> = vec![];
let mut nf: Vec<String> = vec![];
let verbosity = options.verbosity;
let a = clean(input, verbosity);
let a = clean(input, options);
match verbosity {
0 => {}

@ -1,20 +1,33 @@
#[derive(Debug)]
#[derive(Debug, serde::Serialize)]
pub struct Sorted {
#[allow(dead_code)]
pub repo: Vec<String>,
#[allow(dead_code)]
pub aur: Vec<String>,
#[allow(dead_code)]
pub nf: Vec<String>
pub nf: Vec<String>,
}
impl Sorted {
pub fn new(repo: Vec<String>, aur: Vec<String>, nf: Vec<String>) -> Self {
let a: Sorted = Sorted {
repo,
aur,
nf
let a: Sorted = Sorted { repo, aur, nf };
a
}
}
#[derive(Clone, Copy)]
pub struct Options {
pub verbosity: i32,
pub noconfirm: bool,
}
impl Options {
#[allow(dead_code)]
pub fn new(verbosity: i32, noconfirm: bool) -> Self {
let a: Options = Options {
verbosity,
noconfirm,
};
a
}
}
}

@ -1,8 +1,9 @@
mod internal;
mod operations;
use crate::internal::sort;
use clap::{App, Arg, SubCommand};
use crate::internal::{sort, structs::Options};
use clap::{App, AppSettings, Arg, ArgSettings, SubCommand};
use std::process::exit;
fn main() {
let matches = App::new("Amethyst")
@ -11,19 +12,21 @@ fn main() {
.arg(
Arg::with_name("verbose")
.short("v")
.long("verbose")
.multiple(true)
.set(ArgSettings::Global)
.help("Sets the level of verbosity"),
)
.arg(
Arg::with_name("noconfirm")
.long("noconfirm")
.set(ArgSettings::Global)
.help("Complete operation without prompting user"),
)
.subcommand(
SubCommand::with_name("install")
.about("Installs a package from either the AUR or the PacMan-defined repositories")
.aliases(&["-S", "ins"])
.arg(
Arg::with_name("noconfirm")
.short("y")
.long("noconfirm")
.help("Do not ask for confirmation before installing packages"),
)
.arg(
Arg::with_name("package(s)")
.help("The name of the package(s) to install")
@ -35,33 +38,57 @@ fn main() {
.subcommand(
SubCommand::with_name("remove")
.about("Removes a previously installed package")
.aliases(&["-R", "rm"])
.aliases(&["-R", "-Rs", "rm"])
.arg(
Arg::with_name("package(s)")
.help("The name of the package(s) to remove")
.required(true)
.multiple(true)
.index(1),
),
)
.subcommand(
SubCommand::with_name("search")
.about("Searches for the relevant packages in both the AUR and repos.")
.aliases(&["-Ss", "sea"])
.arg(
Arg::with_name("noconfirm")
.short("y")
.long("noconfirm")
.help("Do not ask for confirmation before removing packages"),
Arg::with_name("aur")
.short("a")
.long("aur")
.help("Search only the AUR for the package"),
)
.arg(
Arg::with_name("recursive")
.short("s")
.long("recursive")
.help("Recursively uninstall orphaned dependencies"),
Arg::with_name("repo")
.short("r")
.long("repo")
.help("Searches only local repos for the package"),
)
.arg(
Arg::with_name("package(s)")
.help("The name of the package(s) to remove")
.help("The name of the package to search for")
.required(true)
.multiple(true)
.multiple(false)
.index(1),
),
)
.settings(&[
AppSettings::GlobalVersion,
AppSettings::VersionlessSubcommands,
AppSettings::ArgRequiredElseHelp,
])
.get_matches();
let verbosity: i32 = matches.occurrences_of("verbose") as i32;
let noconfirm: bool = matches.is_present("noconfirm");
let options = Options {
verbosity,
noconfirm,
};
let packages: Vec<String> = matches
.subcommand_matches("install")
.subcommand()
.1
.unwrap()
.values_of("package(s)")
.unwrap()
@ -70,13 +97,52 @@ fn main() {
.collect();
if let true = matches.is_present("install") {
let sorted = sort(&packages, verbosity);
let sorted = sort(&packages, options);
operations::install(sorted.repo, verbosity);
operations::aur_install(sorted.aur, verbosity);
eprintln!(
"Couldn't find packages: {} in repos or the AUR.",
sorted.nf.join(", ")
)
operations::install(sorted.repo, options);
operations::aur_install(sorted.aur, options);
if !sorted.nf.is_empty() {
eprintln!(
"Couldn't find packages: {} in repos or the AUR.",
sorted.nf.join(", ")
);
}
exit(0);
}
if let true = matches.is_present("remove") {
operations::uninstall(packages, options);
exit(0);
}
if let true = matches.is_present("search") {
if matches
.subcommand_matches("search")
.unwrap()
.is_present("aur")
{
operations::aur_search(&packages[0], options);
}
if matches
.subcommand_matches("search")
.unwrap()
.is_present("repo")
{
operations::search(&packages[0], options);
}
if !matches
.subcommand_matches("search")
.unwrap()
.is_present("repo")
&& !matches
.subcommand_matches("search")
.unwrap()
.is_present("aur")
{
operations::search(&packages[0], options);
operations::aur_search(&packages[0], options);
}
exit(0);
}
}

@ -1,4 +1,7 @@
pub fn aur_install(a: Vec<String>, verbosity: i32) {
use crate::Options;
pub fn aur_install(a: Vec<String>, options: Options) {
let verbosity = options.verbosity;
match verbosity {
0 => {}
1 => {

@ -1,15 +1,34 @@
pub fn install(a: Vec<String>, verbosity: i32) {
use crate::Options;
pub fn install(mut a: Vec<String>, options: Options) {
let b = a.clone();
if options.noconfirm {
a.push("--noconfirm".to_string());
}
let verbosity = options.verbosity;
match verbosity {
0 => {},
0 => {}
1 => {
eprintln!("Installing from repos:");
eprintln!("{:?}", &a);
eprintln!("{:?}", &b);
}
_ => {
eprintln!("Installing from repos:");
for b in a {
for b in &a {
eprintln!("{:?}", b);
}
}
}
}
let r = runas::Command::new("pacman")
.arg("-S")
.args(&a)
.status()
.expect("Something has gone wrong.");
if let Some(x) = r.code() {
if verbosity >= 1 {
eprintln!("Installing packages: {:?} exited with code {}.", &b, x)
}
}
}

@ -1,12 +1,26 @@
use crate::Options;
mod aur_install;
mod install;
mod query;
mod search;
mod uninstall;
pub fn install(a: Vec<String>, verbosity: i32) {
install::install(a, verbosity);
pub fn install(a: Vec<String>, options: Options) {
install::install(a, options);
}
pub fn uninstall(a: Vec<String>, options: Options) {
uninstall::uninstall(a, options);
}
pub fn search(a: &str, options: Options) {
search::repo_search(a, options);
}
pub fn aur_install(a: Vec<String>, options: Options) {
aur_install::aur_install(a, options);
}
pub fn aur_install(a: Vec<String>, verbosity: i32) {
aur_install::aur_install(a, verbosity);
pub fn aur_search(a: &str, options: Options) {
search::aur_search(a, options);
}

@ -0,0 +1,44 @@
use crate::internal::rpc::rpcsearch;
use crate::Options;
use std::process::Command;
pub fn aur_search(a: &str, options: Options) {
let verbosity = options.verbosity;
let res = rpcsearch(a.to_string());
if verbosity >= 1 {
eprintln!("Found {} results for \"{}\" in AUR.", res.resultcount, a);
}
for r in &res.results {
println!(
"aur/{} {}\n {}",
r.name,
r.version,
r.description
.as_ref()
.unwrap_or(&"No description.".to_string())
)
}
}
pub fn repo_search(a: &str, options: Options) {
let verbosity = options.verbosity;
let rs = Command::new("pacman")
.arg("-Ss")
.arg(format!("^{}$", &a))
.output()
.expect("Something has gone wrong.");
let str = String::from_utf8(rs.stdout).unwrap();
if verbosity >= 1 {
eprintln!(
"Found {} results for \"{}\" in repos.",
&str.split('\n').count() / 2,
&a
);
}
print!("{}", str);
}

@ -0,0 +1,34 @@
use crate::Options;
pub fn uninstall(mut a: Vec<String>, options: Options) {
let b = a.clone();
if options.noconfirm {
a.push("--noconfirm".to_string());
}
let verbosity = options.verbosity;
match verbosity {
0 => {}
1 => {
eprintln!("Uninstalling:");
eprintln!("{:?}", &b);
}
_ => {
eprintln!("Uninstalling:");
for b in &a {
eprintln!("{}", b);
}
}
}
let r = runas::Command::new("pacman")
.arg("-Rs")
.args(&a)
.status()
.expect("Something has gone wrong.");
if let Some(x) = r.code() {
if verbosity >= 1 {
eprintln!("Uninstalling packages: {:?} exited with code {}.", &b, x)
}
}
}
Loading…
Cancel
Save