130 lines
3.6 KiB
Rust
130 lines
3.6 KiB
Rust
use anyhow::Context;
|
|
use log::{info, LevelFilter};
|
|
use simplelog::{ColorChoice, TermLogger, TerminalMode};
|
|
use std::path::PathBuf;
|
|
use structopt::StructOpt;
|
|
|
|
mod commands;
|
|
mod config;
|
|
mod downloader;
|
|
mod forge;
|
|
mod util;
|
|
|
|
#[derive(StructOpt)]
|
|
struct Opt {
|
|
#[structopt(short, long, parse(from_occurrences), help = "enable verbose logging")]
|
|
verbose: u8,
|
|
|
|
#[structopt(subcommand)]
|
|
cmd: Command,
|
|
}
|
|
|
|
#[derive(StructOpt)]
|
|
enum Command {
|
|
#[structopt(about = "Initializes a new modpack")]
|
|
Init {
|
|
#[structopt(help = "The name of the modpack")]
|
|
modpack_name: String,
|
|
#[structopt(help = "Name of the modpack author")]
|
|
name: String,
|
|
#[structopt(help = "The minecraft version of the modpack")]
|
|
mcversion: String,
|
|
},
|
|
|
|
#[structopt(name = "downloadmods", about = "Downloads mods of the pack")]
|
|
DownloadMods {
|
|
#[structopt(help = "Directory to download mods to")]
|
|
dir: PathBuf,
|
|
#[structopt(short, long, help = "Download all relations and not just mods")]
|
|
all: bool,
|
|
},
|
|
|
|
#[structopt(name = "buildtwitch", about = "Builds a twitch export of the pack")]
|
|
BuildTwitch {
|
|
#[structopt(
|
|
short,
|
|
long,
|
|
help = "Downloads all relations instead of just required ones"
|
|
)]
|
|
all: bool,
|
|
},
|
|
|
|
#[structopt(about = "Deletes artifacts and temporary files")]
|
|
Clean,
|
|
|
|
#[structopt(
|
|
name = "createmodlist",
|
|
about = "Creates a HTML list of the pack's mods."
|
|
)]
|
|
CreateModList {
|
|
#[structopt(
|
|
default_value = "build/modlist.html",
|
|
help = "File to write the mod list to"
|
|
)]
|
|
outfile: PathBuf,
|
|
},
|
|
|
|
#[structopt(
|
|
about = "Imports a twitch manifest file and converts it to an addonscript modpack.json"
|
|
)]
|
|
Import {
|
|
#[structopt(help = "Twitch manifest to convert")]
|
|
infile: PathBuf,
|
|
},
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
let Opt { cmd, verbose } = Opt::from_args();
|
|
|
|
let log_level = match verbose {
|
|
0 => LevelFilter::Off,
|
|
1 => LevelFilter::Info,
|
|
2 => LevelFilter::Debug,
|
|
_ => LevelFilter::Trace,
|
|
};
|
|
|
|
TermLogger::init(
|
|
log_level,
|
|
simplelog::ConfigBuilder::new()
|
|
.set_time_to_local(true)
|
|
.set_target_level(LevelFilter::Error)
|
|
.build(),
|
|
TerminalMode::Stderr,
|
|
ColorChoice::Auto,
|
|
)
|
|
.context("Failed to init logger")?;
|
|
|
|
/// runs a given command, if the first arg is config or manifest, the
|
|
/// manifest or config file is passed to the comand respectively.
|
|
macro_rules! run_cmd {
|
|
(config: $cmd:ident $($args:expr),* $(,)?) => {
|
|
run_cmd!($cmd util::parse_config().await?, $($args),*)
|
|
};
|
|
|
|
(manifest: $cmd:ident $($args:expr),* $(,)?) => {
|
|
run_cmd!($cmd util::parse_config_and_manifest().await?, $($args),*)
|
|
};
|
|
|
|
($cmd:ident $($args:expr),* $(,)?) => {{
|
|
info!("Running command {}", stringify!($cmd));
|
|
commands::$cmd::run($($args),*).await?;
|
|
}}
|
|
}
|
|
|
|
match cmd {
|
|
Command::Init {
|
|
modpack_name,
|
|
name,
|
|
mcversion,
|
|
} => run_cmd!(init modpack_name, name, mcversion),
|
|
Command::DownloadMods { dir, all } => run_cmd!(manifest: downloadmods dir, all),
|
|
Command::BuildTwitch { all } => run_cmd!(manifest: buildtwitch all),
|
|
Command::Clean => run_cmd!(config: clean),
|
|
Command::CreateModList { outfile } => run_cmd!(manifest: createmodlist outfile),
|
|
Command::Import { infile } => run_cmd!(config: import infile),
|
|
}
|
|
|
|
Ok(())
|
|
}
|