initial sorting algorithm

i18n
michal 2 years ago
parent 45402a2100
commit 5b8aa7ff76

@ -0,0 +1,9 @@
pub mod rpc;
pub mod structs;
mod sort;
pub fn sort(a: &[String]) -> structs::Sorted {
sort::sort(a)
}

@ -22,20 +22,33 @@ pub struct SearchResults {
pub results: Vec<Package>,
}
pub fn rpcinfo(pkg: &str) -> Package {
pub struct InfoResults {
pub found: bool,
pub package: Option<Package>
}
pub fn rpcinfo(pkg: String) -> InfoResults {
let res = reqwest::blocking::get(&format!(
"https://aur.archlinux.org/rpc/?v=5&type=info&arg={}",
pkg
)).unwrap();
)).unwrap().json::<SearchResults>().unwrap();
res.json::<SearchResults>().unwrap().results[0].clone()
if res.results.is_empty() {
InfoResults {
found: false,
package: None
}
} else {
InfoResults {
found: true,
package: Some(res.results[0].clone())
}
}
}
pub fn rpcsearch(pkg: &str) -> SearchResults {
let res = reqwest::blocking::get(&format!(
pub fn rpcsearch(pkg: String) -> SearchResults {
reqwest::blocking::get(&format!(
"https://aur.archlinux.org/rpc/?v=5&type=search&arg={}",
pkg
)).unwrap();
res.json().unwrap()
)).unwrap().json().unwrap()
}

@ -0,0 +1,22 @@
use crate::internal::{structs, rpc};
pub fn sort(a: &[String]) -> structs::Sorted {
#[allow(unused_mut)]
let mut repo: Vec<String> = vec![];
let mut aur: Vec<String> = vec![];
let mut nf: Vec<String> = vec![];
for b in a {
if rpc::rpcinfo(b.to_string()).found {
aur.push(b.to_string());
} else {
nf.push(b.to_string());
}
}
structs::Sorted::new(
repo,
aur,
nf
)
}

@ -0,0 +1,20 @@
#[derive(Debug)]
pub struct Sorted {
#[allow(dead_code)]
repo: Vec<String>,
#[allow(dead_code)]
aur: Vec<String>,
#[allow(dead_code)]
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
};
a
}
}

@ -1,5 +1,8 @@
mod rpc;
mod operations;
mod internal;
use clap::{App, Arg, SubCommand};
use crate::internal::sort;
fn main() {
let matches = App::new("Amethyst")
@ -12,27 +15,65 @@ fn main() {
.help("Sets the level of verbosity"),
)
.subcommand(
SubCommand::with_name ("install")
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")
.required(true)
.multiple(true)
.index(1),
),
)
.subcommand(
SubCommand::with_name("remove")
.about("Removes a previously installed package")
.aliases(&["-R", "rm"])
.arg(
Arg::with_name("noconfirm")
.short("y")
.long("noconfirm")
.help("Do not ask for confirmation before installing the package")
.help("Do not ask for confirmation before removing packages"),
)
.arg(
Arg::with_name("package")
.help("The name of the package to install")
Arg::with_name("recursive")
.short("s")
.long("recursive")
.help("Recursively uninstall orphaned dependencies"),
)
.arg(
Arg::with_name("package(s)")
.help("The name of the package(s) to remove")
.required(true)
.index(1)
)
.multiple(true)
.index(1),
),
)
.get_matches();
match matches.occurrences_of("verbose") {
0 => println!("No verbosity"),
1 => println!("Some extra information"),
2 => println!("Plenty of debug text"),
_ => println!("Screensaver mode"),
}
let verbosity = matches.occurrences_of("verbose");
let packages: Vec<String> = matches
.subcommand_matches("install")
.unwrap()
.values_of("package(s)")
.unwrap()
.into_iter().map(|s| s.to_string()).collect();
if let true = matches.is_present("install") {
println!(
"Installing: {}\nVerbosity: {}\n{:?}",
packages.join(", "),
verbosity,
sort(&packages)
);
operations::install(packages);
}
}

@ -0,0 +1,3 @@
pub fn install(a: Vec<String>) {
println!("{:?}", &a);
}

@ -0,0 +1,7 @@
mod install;
mod uninstall;
mod query;
pub fn install(a: Vec<String>) {
install::install(a);
}
Loading…
Cancel
Save