summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorNaz <ndpm13@ch-naseem.com>2025-07-28 10:33:46 +0100
committerNaz <ndpm13@ch-naseem.com>2025-07-28 10:33:46 +0100
commit80e762773af05b7808eef34f1abab40c358c0c9d (patch)
treea233720a9629b3de4b2dfd05fbcd4c1fc48d6424 /src/main.rs
parentdec5ff79991e94a9a04be1e3a4108eec317a8762 (diff)
✨feat: implement basic install and remove commands
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs49
1 files changed, 47 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index e7a11a9..3092c43 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,48 @@
-fn main() {
- println!("Hello, world!");
+use clap::Parser;
+use tokio::fs;
+
+use zap_rs::{AppImage, Cli, Command, Source, SourceMetadata, appimages_dir, index_dir};
+
+#[tokio::main]
+async fn main() -> Result<(), Box<dyn std::error::Error>> {
+ let args = Cli::parse();
+
+ 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"),
+ ),
+ executable: args.executable.unwrap_or(args.appname.clone()),
+ source: Source {
+ identifier: "raw_url".to_string(),
+ meta: SourceMetadata { url: args.from },
+ },
+ };
+
+ 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?;
+ }
+ }
+ 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?;
+ }
+ };
+
+ Ok(())
}