~phate/ppkg

ref: 64f10d2295fc226b59a5839cc1e946298b7589bc ppkg/src/main.rs -rw-r--r-- 1.9 KiB
64f10d22ValleyKnight add filezilla package 6 months ago
                                                                                
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
mod commands;
use commands::{install, list};
use clap::{Arg, SubCommand};
use serde_derive::Deserialize;

#[derive(Deserialize)]
pub struct Config {
    discord: Package,
    filezilla: PackageMultiArch,
    firefox: PackageMultiArch,
    ghcli: PackageMultiArch,
    palemoon: Package,
}

#[derive(Deserialize)]
struct Package {
    package_name: String,
    package_description: String,
    package_version: String,
    package_url: String,
}

#[derive(Deserialize)]
struct PackageMultiArch {
    package_name: String,
    package_description: String,
    package_version: String,
    package_url_32: String,
    package_url_64: String,
}

fn main() {
    let home = std::env::var("HOME").unwrap();
    let home: &str = &home[..];
    let config_path = format!("{}/.ppkg/config.toml", home);
    let config_path: &str = &config_path[..];
    let matches = clap::App::new("ppkg")
        .version("0.1.0")
        .author("Phate6660 <https://Phate6660.codeberg.page>")
        .about("\nPhate's Package Manager, a binary package manager written in Rust.")
        .arg(Arg::with_name("install")
            .short("i")
            .long("install")
            .help("Install a package.")
            .value_name("PKG")
            .takes_value(true))
        .subcommand(SubCommand::with_name("list")
            .about("List packages.")
            .arg(Arg::with_name("available")
                    .short("a")
                    .long("available")
                    .help("List packages available in the repo."))
            .arg(Arg::with_name("installed")
                    .short("i")
                    .long("installed")
                    .help("List Packages currently installed.")))
        .get_matches();
    if matches.is_present("install") {
        install(config_path, home, &matches);
    }
    if let Some(matches) = matches.subcommand_matches("list") {
        list(config_path, home, &matches);
    }
}