summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorNaz <ndpm13@ch-naseem.com>2025-07-29 13:24:35 +0100
committerNaz <ndpm13@ch-naseem.com>2025-07-29 13:24:35 +0100
commitf419a08d2861d76dce3d2a8206d6f1eb24bf1f2e (patch)
tree3590c452abdb9c888fd97c08d848f28e271bd6f1 /src/main.rs
parent4357ff2f74c0b0082741af5e1015ef4da334a430 (diff)
🔧refactor: use separate structs for download logic
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs21
1 files changed, 5 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs
index 4c3d5d7..175b583 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,7 +1,9 @@
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, appimages_dir, index_dir,
+};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -24,23 +26,10 @@ 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?;
- }
+ PackageManager::install(&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?;
+ PackageManager::remove(&args.appname).await?;
}
Command::List => {
let mut appimages = fs::read_dir(index_dir()).await?;