add first draft of a gumdrop implementation

This commit is contained in:
Leo Drachenfeuer 2022-12-19 08:13:44 +01:00
parent 289a06a228
commit 3f6d9223d5
Signed by: dragonleo
GPG key ID: A8338FC081137CF0
4 changed files with 93 additions and 94 deletions

26
Cargo.lock generated
View file

@ -2,10 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "adventofcode"
version = "2022.1.0"
[[package]] [[package]]
name = "aoc" name = "aoc"
version = "2022.1.0" version = "2022.1.0"
@ -23,7 +19,7 @@ name = "aoc22-gdrop"
version = "2022.1.0" version = "2022.1.0"
dependencies = [ dependencies = [
"aoc", "aoc",
"clap", "gumdrop",
] ]
[[package]] [[package]]
@ -96,6 +92,26 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "gumdrop"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bc700f989d2f6f0248546222d9b4258f5b02a171a431f8285a81c08142629e3"
dependencies = [
"gumdrop_derive",
]
[[package]]
name = "gumdrop_derive"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "729f9bd3449d77e7831a18abfb7ba2f99ee813dfd15b8c2167c9a54ba20aa99d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.4.0" version = "0.4.0"

View file

@ -1,20 +1,6 @@
[package]
name = "adventofcode"
version = "2022.1.0"
edition = "2021"
[workspace] [workspace]
members = [ members = [
"aoc22-clap", "aoc22-clap",
"aoc22-gdrop", "aoc22-gdrop",
"aoc" "aoc"
] ]
[[bin]]
name = "aoc22-clap"
path = "aoc22-clap"
[[bin]]
name = "aoc22-gdrop"
path = "aoc22-gdrop"

View file

@ -4,5 +4,5 @@ version = "2022.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
clap = { version = "4.0.29", features = ["derive"] } gumdrop = "0.8"
aoc = {path= "../aoc"} aoc = {path= "../aoc"}

View file

@ -1,93 +1,90 @@
use clap::{arg, Parser, Subcommand};
use aoc::*; use aoc::*;
use gumdrop::Options;
//use std::ffi::OsString; //use std::ffi::OsString;
use std::path::PathBuf; use std::path::PathBuf;
#[derive(Parser)] #[derive(Debug, Options)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
pub struct AdventOfCode2022 { pub struct AdventOfCode2022 {
#[command(subcommand)] // Options here can be accepted with any command (or none at all),
command: Commands, // but they must come before the command name.
/// makes the commands more verbose #[options(help = "print help message")]
#[arg(short, long)] help: bool,
#[options(help = "be verbose")]
verbose: bool, 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(Subcommand)] #[derive(Debug, Options)]
pub enum Commands { pub enum Commands {
/// Solution for the first day #[options(name = "day001", help = "Solution for the first day")]
Day001 { Day001(Day001Options),
file: Option<PathBuf>, #[options(name = "day002", help = "Solution for the second day")]
/// option to get more than the biggest value Day002(BasicOptions2),
#[arg(short, long, default_value_t = 1)] #[options(name = "day003", help = "Solution for day 03")]
top: i32, Day003(BasicOptions),
/// calc the sume of all wanted top positions #[options(name = "day004", help = "Solution for day 04")]
#[arg(long)] Day004(BasicOptions),
total: bool, #[options(name = "day005", help = "Solution for day 05")]
}, Day005(BasicOptions),
/// Solution for the second day #[options(name = "day006", help = "Solution for day 06")]
Day002 { Day006(BasicOptions),
file: Option<PathBuf>, #[options(name = "day007", help = "Solution for day 07")]
#[arg(long)] Day007(BasicOptions),
alt: bool, #[options(name = "day008", help = "Solution for day 08")]
/// select implemetation 0 = nomarl with debug, 1 = only result, 2 iter based Day008(BasicOptions),
#[arg(short, long, default_value_t = 0)] }
mode: u8,
}, #[derive(Debug, Options)]
/// Solution for day 03 pub struct BasicOptions {
Day003 { #[options(free, help = "file with input data")]
file: Option<PathBuf>, file: Option<PathBuf>,
#[arg(long)] #[options(help = "use alternative subfunction for part2")]
alt: bool, alt: bool,
}, }
/// Solution for day 04
Day004 { #[derive(Debug, Options)]
file: Option<PathBuf>, pub struct BasicOptions2 {
#[arg(long)] #[options(free, help = "file with input data")]
alt: bool, file: Option<PathBuf>,
}, #[options(help = "use alternative subfunction for part2")]
/// Solution for day 05 alt: bool,
Day005 { #[options(help = "switch between different implentations")]
file: Option<PathBuf>, mode: u8,
#[arg(long)] }
alt: bool,
}, #[derive(Debug, Options)]
/// Solution for day 06 pub struct Day001Options {
Day006 { #[options(free, help = "file with input data")]
file: Option<PathBuf>, file: Option<PathBuf>,
#[arg(long)] #[options(help = "use alternative subfunction for part2", default = "1")]
alt: bool, top: i32,
}, #[options(help = "calc the sume of all wanted top positions")]
/// Solution for day 07 total: bool,
Day007 {
file: Option<PathBuf>,
#[arg(long)]
alt: bool,
},
/// Solution for day 08
Day008 {
file: Option<PathBuf>,
#[arg(long)]
alt: bool,
},
} }
pub fn execute_cli() { pub fn execute_cli() {
let aoc2022 = AdventOfCode2022::parse(); let aoc2022 = AdventOfCode2022::parse_args_default_or_exit();
match &aoc2022.command { match aoc2022.command {
Commands::Day001 { file, top, total } => subcmd_day001(&file, &top, &total), Some(Commands::Day001(Day001Options { file, top, total })) => {
Commands::Day002 { file, alt, mode } => match mode { Day001Options::p
subcmd_day001(&file, &top, &total)
},
Some(Commands::Day002(BasicOptions2 { file, alt, mode })) => match mode {
0 => subcmd_day002(&file, &alt), 0 => subcmd_day002(&file, &alt),
1 => subcmd_day002_op(&file, &alt), 1 => subcmd_day002_op(&file, &alt),
2 => subcmd_day002_iter(&file, &alt), 2 => subcmd_day002_iter(&file, &alt),
_ => panic!(), _ => panic!(),
}, },
Commands::Day003 { file, alt } => subcmd_day003(&file, &alt), Some(Commands::Day003(BasicOptions { file, alt })) => subcmd_day003(&file, &alt),
Commands::Day004 { file, alt } => subcmd_day004(&file, &alt), Some(Commands::Day004(BasicOptions { file, alt })) => subcmd_day004(&file, &alt),
Commands::Day005 { file, alt } => subcmd_day005(&file, &alt), Some(Commands::Day005(BasicOptions { file, alt })) => subcmd_day005(&file, &alt),
Commands::Day006 { file, alt } => subcmd_day006(&file, &alt), Some(Commands::Day006(BasicOptions { file, alt })) => subcmd_day006(&file, &alt),
Commands::Day007 { file, alt } => subcmd_day007(&file, &alt), Some(Commands::Day007(BasicOptions { file, alt })) => subcmd_day007(&file, &alt),
Commands::Day008 { file, alt } => subcmd_day008(&file, &alt) Some(Commands::Day008(BasicOptions { file, alt })) => subcmd_day008(&file, &alt),
None => unreachable!(),
} }
} }