90 lines
3.2 KiB
Rust
90 lines
3.2 KiB
Rust
use aoc::*;
|
|
use gumdrop::Options;
|
|
//use std::ffi::OsString;
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(Debug, Options)]
|
|
pub struct AdventOfCode2022 {
|
|
// Options here can be accepted with any command (or none at all),
|
|
// but they must come before the command name.
|
|
#[options(help = "print help message")]
|
|
help: bool,
|
|
#[options(help = "be verbose")]
|
|
verbose: bool,
|
|
|
|
// The `command` option will delegate option parsing to the command type,
|
|
// starting at the first free argument.
|
|
#[options(command)]
|
|
command: Option<Commands>,
|
|
}
|
|
|
|
#[derive(Debug, Options)]
|
|
pub enum Commands {
|
|
#[options(name = "day001", help = "Solution for the first day")]
|
|
Day001(Day001Options),
|
|
#[options(name = "day002", help = "Solution for the second day")]
|
|
Day002(BasicOptions2),
|
|
#[options(name = "day003", help = "Solution for day 03")]
|
|
Day003(BasicOptions),
|
|
#[options(name = "day004", help = "Solution for day 04")]
|
|
Day004(BasicOptions),
|
|
#[options(name = "day005", help = "Solution for day 05")]
|
|
Day005(BasicOptions),
|
|
#[options(name = "day006", help = "Solution for day 06")]
|
|
Day006(BasicOptions),
|
|
#[options(name = "day007", help = "Solution for day 07")]
|
|
Day007(BasicOptions),
|
|
#[options(name = "day008", help = "Solution for day 08")]
|
|
Day008(BasicOptions),
|
|
}
|
|
|
|
#[derive(Debug, Options)]
|
|
pub struct BasicOptions {
|
|
#[options(free, help = "file with input data")]
|
|
file: Option<PathBuf>,
|
|
#[options(help = "use alternative subfunction for part2")]
|
|
alt: bool,
|
|
}
|
|
|
|
#[derive(Debug, Options)]
|
|
pub struct BasicOptions2 {
|
|
#[options(free, help = "file with input data")]
|
|
file: Option<PathBuf>,
|
|
#[options(help = "use alternative subfunction for part2")]
|
|
alt: bool,
|
|
#[options(help = "switch between different implentations")]
|
|
mode: u8,
|
|
}
|
|
|
|
#[derive(Debug, Options)]
|
|
pub struct Day001Options {
|
|
#[options(free, help = "file with input data")]
|
|
file: Option<PathBuf>,
|
|
#[options(help = "use alternative subfunction for part2", default = "1")]
|
|
top: i32,
|
|
#[options(help = "calc the sume of all wanted top positions")]
|
|
total: bool,
|
|
}
|
|
|
|
pub fn execute_cli() {
|
|
let aoc2022 = AdventOfCode2022::parse_args_default_or_exit();
|
|
match aoc2022.command {
|
|
Some(Commands::Day001(Day001Options { file, top, total })) => {
|
|
Day001Options::p
|
|
subcmd_day001(&file, &top, &total)
|
|
},
|
|
Some(Commands::Day002(BasicOptions2 { file, alt, mode })) => match mode {
|
|
0 => subcmd_day002(&file, &alt),
|
|
1 => subcmd_day002_op(&file, &alt),
|
|
2 => subcmd_day002_iter(&file, &alt),
|
|
_ => panic!(),
|
|
},
|
|
Some(Commands::Day003(BasicOptions { file, alt })) => subcmd_day003(&file, &alt),
|
|
Some(Commands::Day004(BasicOptions { file, alt })) => subcmd_day004(&file, &alt),
|
|
Some(Commands::Day005(BasicOptions { file, alt })) => subcmd_day005(&file, &alt),
|
|
Some(Commands::Day006(BasicOptions { file, alt })) => subcmd_day006(&file, &alt),
|
|
Some(Commands::Day007(BasicOptions { file, alt })) => subcmd_day007(&file, &alt),
|
|
Some(Commands::Day008(BasicOptions { file, alt })) => subcmd_day008(&file, &alt),
|
|
None => unreachable!(),
|
|
}
|
|
}
|