138 lines
3.6 KiB
Rust
138 lines
3.6 KiB
Rust
use clap::{Parser, Subcommand};
|
|
use log::{info, LevelFilter};
|
|
use miette::{IntoDiagnostic, WrapErr};
|
|
use simplelog::{ColorChoice, TermLogger, TerminalMode};
|
|
use std::path::PathBuf;
|
|
|
|
mod commands;
|
|
mod config;
|
|
mod downloader;
|
|
mod forge;
|
|
mod util;
|
|
|
|
#[derive(Parser)]
|
|
struct Opt {
|
|
/// enable verbose logging
|
|
#[clap(short, long, parse(from_occurrences))]
|
|
verbose: u8,
|
|
|
|
/// add a parameter to be used by the build script
|
|
/// (only useful with lua manifests)
|
|
#[clap(short = 'D')]
|
|
defines: Vec<String>,
|
|
|
|
#[clap(subcommand)]
|
|
cmd: Command,
|
|
}
|
|
|
|
#[derive(Subcommand)]
|
|
enum Command {
|
|
/// Initializes a new modpack
|
|
Init {
|
|
/// The name of the modpack
|
|
modpack_name: String,
|
|
/// Name of the modpack author
|
|
name: String,
|
|
|
|
/// The minecraft version of the modpack
|
|
mcversion: String,
|
|
},
|
|
|
|
/// Downloads mods of the pack
|
|
#[clap(name = "downloadmods")]
|
|
DownloadMods {
|
|
/// Directory to download mods to
|
|
dir: PathBuf,
|
|
|
|
/// Download all relations and not just mods
|
|
#[clap(short, long)]
|
|
all: bool,
|
|
},
|
|
|
|
/// Builds a twitch export of the pack
|
|
#[clap(name = "buildtwitch")]
|
|
BuildTwitch {
|
|
/// Downloads all relations instead of just required ones
|
|
#[clap(short, long)]
|
|
all: bool,
|
|
},
|
|
|
|
/// Deletes artifacts and temporary files
|
|
Clean,
|
|
|
|
/// Creates a HTML list of the pack's mods
|
|
#[clap(name = "createmodlist")]
|
|
CreateModList {
|
|
/// File to write the mod list to
|
|
#[clap(default_value = "build/modlist.html")]
|
|
outfile: PathBuf,
|
|
},
|
|
|
|
/// Imports a twitch manifest file and converts it to an addonscript
|
|
/// modpack.json
|
|
Import {
|
|
/// Twitch manifest to convert
|
|
infile: PathBuf,
|
|
},
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> miette::Result<()> {
|
|
let Opt {
|
|
cmd,
|
|
defines,
|
|
verbose,
|
|
} = Opt::parse();
|
|
|
|
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,
|
|
)
|
|
.into_diagnostic()
|
|
.wrap_err("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(defines, stringify!($cmd)).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(())
|
|
}
|