Something went wrong. Try again.
a better speedrun timer
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748/* Copyright 2024 periwinkle
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.*/
use std::{env, path::PathBuf};
use anyhow::{Result, bail};use getopts::{Options, ParsingStyle};
pub fn get_args() -> Result<(Option<PathBuf>, Option<PathBuf>)> { let args: Vec<_> = env::args().collect(); let prog = args[0].clone(); let mut out = (None, None); let mut opts = Options::new(); opts.parsing_style(ParsingStyle::FloatingFrees); opts.optopt("c", "config-dir", "Path to configuration directory", "DIR"); opts.optopt("s", "split-file", "Path to splits file", "FILE"); opts.optflag("h", "help", "Print this help message"); let matches = match opts.parse(&args[1..]) { Ok(m) => m, Err(e) => { usage(&prog, opts); bail!(e); } }; if matches.opt_present("h") { usage(&prog, opts); bail!("Exiting..."); } if let Some(p) = matches.opt_str("c") { let p = PathBuf::from(p); out.0 = Some(p.canonicalize()?); } if let Some(p) = matches.opt_str("s") { let p = PathBuf::from(p); out.1 = Some(p.canonicalize()?); } Ok(out)}
fn usage(prog: &str, opts: Options) { println!("{}", opts.usage(&format!("Usage: {prog} [options]")));}