lots of stuff
parent
284a0bd21c
commit
62a9b40d48
@ -1,12 +1,14 @@
|
|||||||
|
use crate::Options;
|
||||||
|
|
||||||
mod clean;
|
mod clean;
|
||||||
pub mod rpc;
|
pub mod rpc;
|
||||||
mod sort;
|
mod sort;
|
||||||
pub mod structs;
|
pub mod structs;
|
||||||
|
|
||||||
pub fn sort(a: &[String], verbosity: i32) -> structs::Sorted {
|
pub fn sort(a: &[String], options: Options) -> structs::Sorted {
|
||||||
sort::sort(a, verbosity)
|
sort::sort(a, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clean(a: &[String], verbosity: i32) -> Vec<String> {
|
pub fn clean(a: &[String], options: Options) -> Vec<String> {
|
||||||
clean::clean(a, verbosity)
|
clean::clean(a, options)
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,33 @@
|
|||||||
#[derive(Debug)]
|
#[derive(Debug, serde::Serialize)]
|
||||||
pub struct Sorted {
|
pub struct Sorted {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub repo: Vec<String>,
|
pub repo: Vec<String>,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub aur: Vec<String>,
|
pub aur: Vec<String>,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub nf: Vec<String>
|
pub nf: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sorted {
|
impl Sorted {
|
||||||
pub fn new(repo: Vec<String>, aur: Vec<String>, nf: Vec<String>) -> Self {
|
pub fn new(repo: Vec<String>, aur: Vec<String>, nf: Vec<String>) -> Self {
|
||||||
let a: Sorted = Sorted {
|
let a: Sorted = Sorted { repo, aur, nf };
|
||||||
repo,
|
a
|
||||||
aur,
|
}
|
||||||
nf
|
}
|
||||||
|
|
||||||
|
#[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
|
a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
match verbosity {
|
||||||
0 => {},
|
0 => {}
|
||||||
1 => {
|
1 => {
|
||||||
eprintln!("Installing from repos:");
|
eprintln!("Installing from repos:");
|
||||||
eprintln!("{:?}", &a);
|
eprintln!("{:?}", &b);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
eprintln!("Installing from repos:");
|
eprintln!("Installing from repos:");
|
||||||
for b in a {
|
for b in &a {
|
||||||
eprintln!("{:?}", b);
|
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 aur_install;
|
||||||
mod install;
|
mod install;
|
||||||
mod query;
|
mod search;
|
||||||
mod uninstall;
|
mod uninstall;
|
||||||
|
|
||||||
pub fn install(a: Vec<String>, verbosity: i32) {
|
pub fn install(a: Vec<String>, options: Options) {
|
||||||
install::install(a, verbosity);
|
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) {
|
pub fn aur_search(a: &str, options: Options) {
|
||||||
aur_install::aur_install(a, verbosity);
|
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…
Reference in New Issue