Files
AstralRinth/theseus/examples/download-pack.rs
Danielle d1070ca213 Initial draft of profile metadata format & CLI (#17)
* Initial draft of profile metadata format

* Remove records, add Clippy to Nix, fix Clippy error

* Work on profile definition

* BREAKING: Make global settings consistent with profile settings

* Add builder methods & format

* Integrate launching with profiles

* Add profile loading

* Launching via profile, API tweaks, and yak shaving

* Incremental update, committing everything due to personal system maintainance

* Prepare for review cycle

* Remove reminents of experimental work

* CLI: allow people to override the non-empty directory check

* Fix mistake in previous commit

* Handle trailing whitespace and newlines in prompts

* Revamp prompt to use dialoguer and support defaults

* Make requested changes
2022-03-28 18:41:35 -07:00

56 lines
1.3 KiB
Rust

use std::{path::PathBuf, time::Instant};
use argh::FromArgs;
use theseus::modpack::{fetch_modpack, pack::ModpackSide};
#[derive(FromArgs)]
/// Simple modpack download
struct ModpackDownloader {
/// where to download to
#[argh(positional)]
url: String,
/// where to put the resulting pack
#[argh(option, short = 'o')]
output: Option<PathBuf>,
/// the sha1 hash, if you want it checked
#[argh(option, short = 'c')]
hash: Option<String>,
/// use verbose logging
#[argh(switch, short = 'v')]
verbose: bool,
}
// Simple logging helper
fn debug(msg: &str, verbose: bool) {
if verbose {
println!("{}", msg);
}
}
#[tokio::main]
pub async fn main() {
let args = argh::from_env::<ModpackDownloader>();
let dest = args.output.unwrap_or(PathBuf::from("./pack-download/"));
debug(
&format!(
"Downloading pack {} to {}",
args.url,
dest.to_str().unwrap_or("?")
),
args.verbose,
);
let start = Instant::now();
fetch_modpack(&args.url, args.hash.as_deref(), &dest, ModpackSide::Client)
.await
.unwrap();
let end = start.elapsed();
println!("Download completed in {} seconds", end.as_secs_f32());
debug("Done!", args.verbose);
}