From b0d4e60e525e2438e02fa3e3b5ffaba374a03a71 Mon Sep 17 00:00:00 2001 From: Naz Date: Fri, 8 Aug 2025 15:52:51 +0100 Subject: =?UTF-8?q?=F0=9F=94=A7refactor:=20move=20AppImage=20construction?= =?UTF-8?q?=20logic=20to=20new()=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/appimage.rs | 25 +++++++++++++++++++++++++ src/main.rs | 18 +++--------------- 2 files changed, 28 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/appimage.rs b/src/appimage.rs index 5d0f8e5..c3f61b1 100644 --- a/src/appimage.rs +++ b/src/appimage.rs @@ -1,6 +1,8 @@ use serde::{Deserialize, Serialize}; use std::path::PathBuf; +use crate::InstallArgs; + #[derive(Debug, Serialize, Deserialize)] pub struct AppImage { pub file_path: PathBuf, @@ -18,3 +20,26 @@ pub struct Source { pub struct SourceMetadata { pub url: String, } + +impl AppImage { + pub fn new(options: &InstallArgs) -> Self { + Self { + file_path: PathBuf::new(), + executable: options + .executable + .as_ref() + .unwrap_or(&options.appname) + .to_string(), + source: Source { + identifier: if options.github { + "git.github".to_string() + } else { + "raw_url".to_string() + }, + meta: SourceMetadata { + url: options.from.clone(), + }, + }, + } + } +} diff --git a/src/main.rs b/src/main.rs index e4bc296..3081598 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,7 @@ use clap::Parser; use colored::Colorize; -use std::path::PathBuf; -use zap_rs::{AppImage, Cli, Command, PackageManager, Result, Source, SourceMetadata}; +use zap_rs::{AppImage, Cli, Command, PackageManager, Result}; async fn run() -> Result<()> { let args = Cli::parse(); @@ -10,20 +9,9 @@ async fn run() -> Result<()> { match args.command { Command::Install(args) => { - let mut options = AppImage { - file_path: PathBuf::new(), - executable: args.executable.unwrap_or(args.appname.clone()), - source: Source { - identifier: if args.github { - "git.github".to_string() - } else { - "raw_url".to_string() - }, - meta: SourceMetadata { url: args.from }, - }, - }; + let mut appimage = AppImage::new(&args); - pm.install(&mut options, &args.appname).await?; + pm.install(&mut appimage, &args.appname).await?; } Command::Remove(args) => { pm.remove(&args.appname).await?; -- cgit v1.2.3