1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
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(())
}
|