From 67c31725c10e4e529b2ffef37165bbd5bb95dd5b Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sun, 29 Dec 2024 11:50:58 +0100 Subject: [PATCH] fix + test --- src/lib.rs | 1 + src/main.rs | 3 +-- src/pkg/package.rs | 20 +++++++++++++++++++- src/routes/mod.rs | 4 ++-- 4 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 src/lib.rs diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..38fda62 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1 @@ +pub mod pkg; diff --git a/src/main.rs b/src/main.rs index 3517132..66aa596 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,11 +9,10 @@ use based::get_pg; use based::page::{Shell, render_page}; use based::request::{RequestContext, StringResponse}; use maud::html; -use pkg::Repository; +use pacco::pkg::Repository; use rocket::get; use rocket::routes; -pub mod pkg; pub mod routes; #[get("/")] diff --git a/src/pkg/package.rs b/src/pkg/package.rs index 8f65a93..5750650 100644 --- a/src/pkg/package.rs +++ b/src/pkg/package.rs @@ -27,6 +27,24 @@ impl Package { } /// Extract values from a package filename + /// + /// # Example + /// + /// ``` + /// use pacco::pkg::Package; + /// + /// let (name, version, rel, arch) = Package::extract_pkg_name("pkg-ver-rel-x86_64.pkg.tar.zst").unwrap(); + /// assert_eq!(name, "pkg"); + /// assert_eq!(version, "ver"); + /// assert_eq!(rel, "rel"); + /// assert_eq!(arch, pacco::pkg::arch::Architecture::x86_64); + /// + /// let (name, version, rel, arch) = Package::extract_pkg_name("my-pkg-ver-rel-x86_64.pkg.tar.zst").unwrap(); + /// assert_eq!(name, "my-pkg"); + /// assert_eq!(version, "ver"); + /// assert_eq!(rel, "rel"); + /// assert_eq!(arch, pacco::pkg::arch::Architecture::x86_64); + /// ``` pub fn extract_pkg_name(file_name: &str) -> Option<(String, String, String, Architecture)> { // Extract (assuming the filename is "---.pkg.tar.zst") let mut splitted = file_name.split('-').collect::>(); @@ -38,7 +56,7 @@ impl Package { let relation = splitted.pop()?; let version = splitted.pop()?; - let pkg_name = splitted.join(" "); + let pkg_name = splitted.join("-"); return Some(( pkg_name, diff --git a/src/routes/mod.rs b/src/routes/mod.rs index d0d2d7a..14cfbac 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -5,8 +5,8 @@ use rocket::tokio::io::AsyncReadExt; use rocket::{FromForm, get, post}; use serde_json::json; -use crate::pkg::arch::Architecture; -use crate::pkg::{Package, Repository}; +use pacco::pkg::arch::Architecture; +use pacco::pkg::{Package, Repository}; // /pkg/// // /pkg///