summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: e4bc2964515b85fbf5a61dfd4659f4dcd4387015 (plain)
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
use clap::Parser;
use colored::Colorize;
use std::path::PathBuf;

use zap_rs::{AppImage, Cli, Command, PackageManager, Result, Source, SourceMetadata};

async fn run() -> Result<()> {
    let args = Cli::parse();
    let pm = PackageManager::new();

    match args.command {
        Command::Install(args) => {
            let mut options = AppImage {
                file_path: PathBuf::new(),
                executable: args.executable.unwrap_or(args.appname.clone()),
                source: Source {
                    identifier: if args.github {
                        "git.github".to_string()
                    } else {
                        "raw_url".to_string()
                    },
                    meta: SourceMetadata { url: args.from },
                },
            };

            pm.install(&mut options, &args.appname).await?;
        }
        Command::Remove(args) => {
            pm.remove(&args.appname).await?;
        }
        Command::List => {
            pm.list().await?;
        }
    };

    Ok(())
}

#[tokio::main]
async fn main() {
    if let Err(e) = run().await {
        eprintln!("{} {}", "Error:".red().bold(), e);
        std::process::exit(1);
    }
}