added verbosity parsing and debug messages

i18n
michal 2 years ago
parent 5b8aa7ff76
commit 4b2272009f

@ -2,8 +2,8 @@ pub mod rpc;
pub mod structs; pub mod structs;
mod sort; mod sort;
pub fn sort(a: &[String]) -> structs::Sorted { pub fn sort(a: &[String], verbosity: i32) -> structs::Sorted {
sort::sort(a) sort::sort(a, verbosity)
} }

@ -1,15 +1,35 @@
use crate::internal::{structs, rpc}; use crate::internal::{structs, rpc};
pub fn sort(a: &[String]) -> structs::Sorted { pub fn sort(a: &[String], verbosity: i32) -> structs::Sorted {
#[allow(unused_mut)] #[allow(unused_mut)]
let mut repo: Vec<String> = vec![]; let mut repo: Vec<String> = vec![];
let mut aur: Vec<String> = vec![]; let mut aur: Vec<String> = vec![];
let mut nf: Vec<String> = vec![]; let mut nf: Vec<String> = vec![];
match verbosity {
0 => {}
1 => {
eprintln!("Sorting:");
eprintln!("{:?}", a);
}
_ => {
eprintln!("Sorting:");
for b in a {
eprintln!("{:?}", b);
}
}
}
for b in a { for b in a {
if rpc::rpcinfo(b.to_string()).found { if rpc::rpcinfo(b.to_string()).found {
if verbosity >= 1 {
eprintln!("{} found in AUR.", b);
}
aur.push(b.to_string()); aur.push(b.to_string());
} else { } else {
if verbosity >= 1 {
eprintln!("{} not found.", b);
}
nf.push(b.to_string()); nf.push(b.to_string());
} }
} }

@ -1,11 +1,11 @@
#[derive(Debug)] #[derive(Debug)]
pub struct Sorted { pub struct Sorted {
#[allow(dead_code)] #[allow(dead_code)]
repo: Vec<String>, pub repo: Vec<String>,
#[allow(dead_code)] #[allow(dead_code)]
aur: Vec<String>, pub aur: Vec<String>,
#[allow(dead_code)] #[allow(dead_code)]
nf: Vec<String> pub nf: Vec<String>
} }
impl Sorted { impl Sorted {

@ -58,7 +58,7 @@ fn main() {
) )
.get_matches(); .get_matches();
let verbosity = matches.occurrences_of("verbose"); let verbosity: i32 = matches.occurrences_of("verbose") as i32;
let packages: Vec<String> = matches let packages: Vec<String> = matches
.subcommand_matches("install") .subcommand_matches("install")
@ -68,12 +68,7 @@ fn main() {
.into_iter().map(|s| s.to_string()).collect(); .into_iter().map(|s| s.to_string()).collect();
if let true = matches.is_present("install") { if let true = matches.is_present("install") {
println!( let sorted = sort(&packages, verbosity);
"Installing: {}\nVerbosity: {}\n{:?}", operations::install(sorted.repo, verbosity);
packages.join(", "),
verbosity,
sort(&packages)
);
operations::install(packages);
} }
} }

@ -1,3 +1,15 @@
pub fn install(a: Vec<String>) { pub fn install(a: Vec<String>, verbosity: i32) {
println!("{:?}", &a); match verbosity {
0 => {},
1 => {
eprintln!("Installing from repos:");
eprintln!("{:?}", &a);
}
_ => {
eprintln!("Installing from repos:");
for b in a {
eprintln!("{:?}", b);
}
}
}
} }

@ -2,6 +2,6 @@ mod install;
mod uninstall; mod uninstall;
mod query; mod query;
pub fn install(a: Vec<String>) { pub fn install(a: Vec<String>, verbosity: i32) {
install::install(a); install::install(a, verbosity);
} }
Loading…
Cancel
Save