From decf1f14e67053123023ba1fc5dd0434baf8180e Mon Sep 17 00:00:00 2001 From: Tristan Smith Date: Thu, 12 Sep 2024 00:43:44 -0400 Subject: [PATCH] currently builds and searches the AUR --- .gitignore | 2 ++ Cargo.toml | 8 ++++++++ src/main.rs | 20 ++++++++++++++++++++ src/search.rs | 31 +++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 src/main.rs create mode 100644 src/search.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..65671e3 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "raur" +version = "0.1.0" +edition = "2021" + +[dependencies] +aur-rs = "0.1.1" +tokio = { version = "1", features = ["full"] } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..4a51bea --- /dev/null +++ b/src/main.rs @@ -0,0 +1,20 @@ +use std::env; + +mod search; + +#[tokio::main] +async fn main() { + // Collect command-line arguments + let args: Vec = env::args().collect(); + + // Check if the correct number of arguments is passed + if args.len() != 2 { + eprintln!("Usage: raur "); + return; + } + + let package_name = &args[1]; + + // Call the async search function and await it + search::search(package_name).await; +} diff --git a/src/search.rs b/src/search.rs new file mode 100644 index 0000000..7272554 --- /dev/null +++ b/src/search.rs @@ -0,0 +1,31 @@ +use aur_rs::{Request, ReturnData}; + +pub async fn search(package_name: &str) { + println!("Searching for package: {}\n", package_name); + + search_package_by_name(package_name).await; +} + +pub async fn search_package_by_name(package_name: &str) { + let request = Request::default(); + let response: ReturnData = request + .search_package_by_name(package_name) + .await + .expect("Failed to search package"); + + if response.results.is_empty() { + eprintln!("No results found"); + return; + } + + for package in &response.results { + println!("Package name: {}", package.name); + + // Print the package description if it exists + if let Some(description) = &package.description { + println!("Description: {}", description); + } + + println!(); + } +}