diff options
| author | Naz <ndpm13@ch-naseem.com> | 2025-08-08 15:52:51 +0100 |
|---|---|---|
| committer | Naz <ndpm13@ch-naseem.com> | 2025-08-08 15:52:51 +0100 |
| commit | b0d4e60e525e2438e02fa3e3b5ffaba374a03a71 (patch) | |
| tree | b9a637848f690de879dd11dd6f667a52c49c3a6f | |
| parent | 32bda21c93754359335f8826b5edf931d551d2e8 (diff) | |
🔧refactor: move AppImage construction logic to new() method
| -rw-r--r-- | src/appimage.rs | 25 | ||||
| -rw-r--r-- | src/main.rs | 18 |
2 files changed, 28 insertions, 15 deletions
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?; |
