diff options
| author | Naz <ndpm13@ch-naseem.com> | 2025-07-30 07:11:24 +0100 |
|---|---|---|
| committer | Naz <ndpm13@ch-naseem.com> | 2025-07-30 07:11:24 +0100 |
| commit | df40ab0fd7d9641297833dc7e0691522c25e2bc9 (patch) | |
| tree | b185168ceedb4f71b255e7e61a365566da41538d /src/main.rs | |
| parent | d3c84b04d7a46735dd19a2dae9448e811a609291 (diff) | |
| parent | 11a86042e73bb0eecad61ac6e636dd98563167f5 (diff) | |
Merge pull request '🔧refactor: separate download logic from AppImage struct' (#11) from feat/issue-7 into main
Reviewed-on: https://git.ch-naseem.com/ndpm13/zap-rs/pulls/11
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/src/main.rs b/src/main.rs index 4c3d5d7..1d9505b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,22 +1,18 @@ +use std::path::PathBuf; + use clap::Parser; -use tokio::fs; -use zap_rs::{AppImage, Cli, Command, Source, SourceMetadata, appimages_dir, index_dir}; +use zap_rs::{AppImage, Cli, Command, PackageManager, Source, SourceMetadata}; #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let args = Cli::parse(); + let pm = PackageManager::new(); match args.command { Command::Install(args) => { - let options = AppImage { - file_path: appimages_dir().join( - args.from - .split('/') - .next_back() - .filter(|s| !s.is_empty()) - .unwrap_or("app.AppImage"), - ), + let mut options = AppImage { + file_path: PathBuf::new(), executable: args.executable.unwrap_or(args.appname.clone()), source: Source { identifier: "raw_url".to_string(), @@ -24,32 +20,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { }, }; - if index_dir() - .join(format!("{}.json", &options.executable)) - .exists() - { - eprintln!("{} is already installed.", &options.executable); - } else { - options.download_from_url().await?; - options.save_to_index(&args.appname).await?; - options.create_symlink().await?; - } + pm.install(&mut options, &args.appname).await?; } Command::Remove(args) => { - let index_file_path = index_dir().join(format!("{}.json", args.appname)); - let index_file_content = fs::read_to_string(&index_file_path).await?; - let appimage: AppImage = serde_json::from_str(&index_file_content)?; - - appimage.remove().await?; + pm.remove(&args.appname).await?; } Command::List => { - let mut appimages = fs::read_dir(index_dir()).await?; - - while let Some(appimage) = appimages.next_entry().await? { - if let Some(name) = appimage.file_name().to_str() { - println!("- {}", name.strip_suffix(".json").unwrap()); - } - } + pm.list().await?; } }; |
