add first draft of a gumdrop implementation
This commit is contained in:
parent
289a06a228
commit
3f6d9223d5
4 changed files with 93 additions and 94 deletions
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -2,10 +2,6 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "adventofcode"
|
||||
version = "2022.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "aoc"
|
||||
version = "2022.1.0"
|
||||
|
@ -23,7 +19,7 @@ name = "aoc22-gdrop"
|
|||
version = "2022.1.0"
|
||||
dependencies = [
|
||||
"aoc",
|
||||
"clap",
|
||||
"gumdrop",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -96,6 +92,26 @@ dependencies = [
|
|||
"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]]
|
||||
name = "heck"
|
||||
version = "0.4.0"
|
||||
|
|
14
Cargo.toml
14
Cargo.toml
|
@ -1,20 +1,6 @@
|
|||
[package]
|
||||
name = "adventofcode"
|
||||
version = "2022.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"aoc22-clap",
|
||||
"aoc22-gdrop",
|
||||
"aoc"
|
||||
]
|
||||
|
||||
[[bin]]
|
||||
name = "aoc22-clap"
|
||||
path = "aoc22-clap"
|
||||
|
||||
[[bin]]
|
||||
name = "aoc22-gdrop"
|
||||
path = "aoc22-gdrop"
|
|
@ -4,5 +4,5 @@ version = "2022.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.0.29", features = ["derive"] }
|
||||
gumdrop = "0.8"
|
||||
aoc = {path= "../aoc"}
|
||||
|
|
|
@ -1,93 +1,90 @@
|
|||
use clap::{arg, Parser, Subcommand};
|
||||
use aoc::*;
|
||||
use gumdrop::Options;
|
||||
//use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
#[command(propagate_version = true)]
|
||||
#[derive(Debug, Options)]
|
||||
pub struct AdventOfCode2022 {
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
/// makes the commands more verbose
|
||||
#[arg(short, long)]
|
||||
// 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(Subcommand)]
|
||||
#[derive(Debug, Options)]
|
||||
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,
|
||||
},
|
||||
#[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();
|
||||
match &aoc2022.command {
|
||||
Commands::Day001 { file, top, total } => subcmd_day001(&file, &top, &total),
|
||||
Commands::Day002 { file, alt, mode } => match mode {
|
||||
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!(),
|
||||
},
|
||||
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)
|
||||
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!(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue