summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 0898daf9d3f2603baacf97d3e886a09774fda461 (plain) (blame)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*!
 * Thinking about how best to design this...
 * 
 * I want to do something different from the original modpackman, mostly in the realm of "i want to make it easier and more portable" (hence rust).
 * 
 * ## Interface
 * I want this to be a tad easier to use. There should be one binary to run that does both dependency fixing for modpacks and installation. That binary should have the following subcommands
 * - apply_updates
 * - check_updates
 * - install
 * 
 * All of these commands should assume that the CWD contains a valid pack.toml and that the pack is valid.
 * 
 * I'm not sure how packaging this is going to work but it should be fun!
 */



use std::process::exit;

use clap::{Parser, Subcommand};
mod errors;
mod cli;
mod util;

use cli::{updates::check_updates, install};
use errors::CliError;
use util::{PackConfig, read_pack_config};
use tracing_subscriber::prelude::*;

#[derive(Parser)]
#[command(author, version, about)]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand, Clone, Copy)]
enum Commands {
    ApplyUpdates { },
    CheckUpdates { },
    /// Installs CWD's pack definition into the local .minecraft folder
    Install { }
}

#[tokio::main]
async fn main() {
    color_eyre::install().unwrap();
    tracing_subscriber::registry()
    .with(tracing_subscriber::EnvFilter::new(
        std::env::var("RUST_LOG").unwrap_or_else(|_| "modpackman_ng=debug,hyper=debug".into()),
    ))
    .with(tracing_subscriber::fmt::layer())
    .init();
    let cli = Cli::parse();

    let cfg: PackConfig = match read_pack_config() {
        Ok(c) => c,
        Err(e) => {
            println!("Error reading config: {:?}", e);
            exit(-1);
        }
    };

    let res: Result<(), CliError> = match &cli.command {
        Commands::ApplyUpdates {  } => {
            cli::updates::apply_updates(cfg).await
        },
        Commands::CheckUpdates {  } => {
            check_updates(cfg).await
        },
        Commands::Install {  } => {
            install::install()
        }
    };

    match res {
        Err(e) => {
            println!("{:?}", e);
        },
        Ok(()) => { },
    } 
}