diff options
| author | Naz <ndpm13@ch-naseem.com> | 2025-07-28 09:50:56 +0100 |
|---|---|---|
| committer | Naz <ndpm13@ch-naseem.com> | 2025-07-28 09:50:56 +0100 |
| commit | 91813e3f6a9b93b92fb4b99d2e9512d41726c9d9 (patch) | |
| tree | 700a978fb913a08e4bbbccdcc202aac70e40e7fe /src | |
| parent | a77624b8615a10d6aaba186dcd6bbb15b1419397 (diff) | |
✨feat: add AppImage removal functionality
Diffstat (limited to 'src')
| -rw-r--r-- | src/args.rs | 9 | ||||
| -rw-r--r-- | src/types.rs | 19 |
2 files changed, 24 insertions, 4 deletions
diff --git a/src/args.rs b/src/args.rs index 274bb1e..7f7ca3a 100644 --- a/src/args.rs +++ b/src/args.rs @@ -13,6 +13,10 @@ pub enum Command { /// Installs an AppImage #[command(name = "install", alias = "i")] Install(InstallArgs), + + /// Removes an AppImage + #[command(name = "remove", alias = "rm")] + Remove(RemoveArgs), } #[derive(Debug, Args)] @@ -27,3 +31,8 @@ pub struct InstallArgs { #[arg(long)] pub executable: Option<String>, } + +#[derive(Debug, Args)] +pub struct RemoveArgs { + pub appname: String, +} diff --git a/src/types.rs b/src/types.rs index f0cbfd4..be3f3ed 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,24 +1,24 @@ use futures_util::StreamExt; -use serde::Serialize; +use serde::{Serialize, Deserialize}; use std::path::PathBuf; use tokio::{fs, io::AsyncWriteExt}; use crate::{appimages_dir, index_dir, make_progress_bar}; -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Deserialize)] pub struct AppImage { pub file_path: PathBuf, pub executable: String, pub source: Source, } -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Deserialize)] pub struct Source { pub identifier: String, pub meta: SourceMetadata, } -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Deserialize)] pub struct SourceMetadata { pub url: String, } @@ -92,4 +92,15 @@ impl AppImage { Ok(()) } + pub async fn remove(&self) -> Result<(), Box<dyn std::error::Error>> { + let home = std::env::var("HOME")?; + let symlink_path = PathBuf::from(home).join(".local/bin").join(&self.executable); + let index_path = index_dir().join(format!("{}.json", &self.executable)); + + fs::remove_file(&self.file_path).await?; + fs::remove_file(symlink_path).await?; + fs::remove_file(index_path).await?; + + Ok(()) + } } |
