adventofcode2022/aoc22-gdrop/src/cli/mod.rs

93 lines
2.5 KiB
Rust

use clap::{arg, Parser, Subcommand};
use aoc::*;
//use std::ffi::OsString;
use std::path::PathBuf;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
pub struct AdventOfCode2022 {
#[command(subcommand)]
command: Commands,
/// makes the commands more verbose
#[arg(short, long)]
verbose: bool,
}
#[derive(Subcommand)]
pub enum Commands {
/// Solution for the first day
Day001 {
file: Option<PathBuf>,
/// option to get more than the biggest value
#[arg(short, long, default_value_t = 1)]
top: i32,
/// calc the sume of all wanted top positions
#[arg(long)]
total: bool,
},
/// Solution for the second day
Day002 {
file: Option<PathBuf>,
#[arg(long)]
alt: bool,
/// select implemetation 0 = nomarl with debug, 1 = only result, 2 iter based
#[arg(short, long, default_value_t = 0)]
mode: u8,
},
/// Solution for day 03
Day003 {
file: Option<PathBuf>,
#[arg(long)]
alt: bool,
},
/// Solution for day 04
Day004 {
file: Option<PathBuf>,
#[arg(long)]
alt: bool,
},
/// Solution for day 05
Day005 {
file: Option<PathBuf>,
#[arg(long)]
alt: bool,
},
/// Solution for day 06
Day006 {
file: Option<PathBuf>,
#[arg(long)]
alt: bool,
},
/// Solution for day 07
Day007 {
file: Option<PathBuf>,
#[arg(long)]
alt: bool,
},
/// Solution for day 08
Day008 {
file: Option<PathBuf>,
#[arg(long)]
alt: bool,
},
}
pub fn execute_cli() {
let aoc2022 = AdventOfCode2022::parse();
match &aoc2022.command {
Commands::Day001 { file, top, total } => subcmd_day001(&file, &top, &total),
Commands::Day002 { file, alt, mode } => match mode {
0 => subcmd_day002(&file, &alt),
1 => subcmd_day002_op(&file, &alt),
2 => subcmd_day002_iter(&file, &alt),
_ => panic!(),
},
Commands::Day003 { file, alt } => subcmd_day003(&file, &alt),
Commands::Day004 { file, alt } => subcmd_day004(&file, &alt),
Commands::Day005 { file, alt } => subcmd_day005(&file, &alt),
Commands::Day006 { file, alt } => subcmd_day006(&file, &alt),
Commands::Day007 { file, alt } => subcmd_day007(&file, &alt),
Commands::Day008 { file, alt } => subcmd_day008(&file, &alt)
}
}