From f091f19a559189ab82f7da8b5691f4cb7c66f435 Mon Sep 17 00:00:00 2001 From: Leo Drachenfeuer Date: Sat, 10 Dec 2022 14:25:12 +0100 Subject: [PATCH 1/9] simplify function import for subcomands --- src/cli/commands/mod.rs | 60 ++++++++++++++++++++++++----------------- src/cli/mod.rs | 9 +------ 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/cli/commands/mod.rs b/src/cli/commands/mod.rs index 080c1c0..e73cfd1 100644 --- a/src/cli/commands/mod.rs +++ b/src/cli/commands/mod.rs @@ -1,25 +1,35 @@ -pub mod day001; -pub mod day002; -pub mod day003; -pub mod day004; -pub mod day005; -pub mod day006; -pub mod day007; -pub mod day008; -pub mod day009; -//pub mod day010; -//pub mod day011; -//pub mod day012; -//pub mod day013; -//pub mod day014; -//pub mod day015; -//pub mod day016; -//pub mod day017; -//pub mod day018; -//pub mod day019; -//pub mod day020; -//pub mod day021; -//pub mod day022; -//pub mod day023; -//pub mod day024; -//pub mod day025; +mod day001; +mod day002; +mod day003; +mod day004; +mod day005; +mod day006; +mod day007; +mod day008; +mod day009; +//mod day010; +//mod day011; +//mod day012; +//mod day013; +//mod day014; +//mod day015; +//mod day016; +//mod day017; +//mod day018; +//mod day019; +//mod day020; +//mod day021; +//mod day022; +//mod day023; +//mod day024; +//mod day025; + +pub use day001::*; +pub use day002::*; +pub use day003::*; +pub use day004::*; +pub use day005::*; +pub use day006::*; +pub use day007::*; +pub use day008::*; +pub use day009::*; diff --git a/src/cli/mod.rs b/src/cli/mod.rs index be32135..a506aca 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -1,13 +1,6 @@ mod commands; use clap::{arg, Parser, Subcommand}; -use commands::day001::*; -use commands::day002::*; -use commands::day003::*; -use commands::day004::*; -use commands::day005::*; -use commands::day006::*; -use commands::day007::*; -use commands::day008::*; +use commands::*; //use std::ffi::OsString; use std::path::PathBuf; From 8b16296d5efa7dd060af42ead6561c4b0c4533eb Mon Sep 17 00:00:00 2001 From: Leo Drachenfeuer Date: Tue, 13 Dec 2022 05:02:02 +0100 Subject: [PATCH 2/9] refactor projekt to implement and test other cli libs --- Cargo.lock | 15 ++++++++++----- Cargo.toml | 12 +++++------- aoc/Cargo.toml | 6 ++++++ aoc/src/lib.rs | 4 ++++ {src => aoc/src}/util.rs | 0 {src/cli/commands => aoc/src/year2022}/day001.rs | 0 {src/cli/commands => aoc/src/year2022}/day002.rs | 0 {src/cli/commands => aoc/src/year2022}/day003.rs | 0 {src/cli/commands => aoc/src/year2022}/day004.rs | 0 {src/cli/commands => aoc/src/year2022}/day005.rs | 0 {src/cli/commands => aoc/src/year2022}/day006.rs | 0 {src/cli/commands => aoc/src/year2022}/day007.rs | 0 {src/cli/commands => aoc/src/year2022}/day008.rs | 0 {src/cli/commands => aoc/src/year2022}/day009.rs | 0 {src/cli/commands => aoc/src/year2022}/day010.rs | 0 {src/cli/commands => aoc/src/year2022}/day011.rs | 0 {src/cli/commands => aoc/src/year2022}/day012.rs | 0 {src/cli/commands => aoc/src/year2022}/day013.rs | 0 {src/cli/commands => aoc/src/year2022}/day014.rs | 0 {src/cli/commands => aoc/src/year2022}/day015.rs | 0 {src/cli/commands => aoc/src/year2022}/day016.rs | 0 {src/cli/commands => aoc/src/year2022}/day017.rs | 0 {src/cli/commands => aoc/src/year2022}/day018.rs | 0 {src/cli/commands => aoc/src/year2022}/day019.rs | 0 {src/cli/commands => aoc/src/year2022}/day020.rs | 0 {src/cli/commands => aoc/src/year2022}/day021.rs | 0 {src/cli/commands => aoc/src/year2022}/day022.rs | 0 {src/cli/commands => aoc/src/year2022}/day023.rs | 0 {src/cli/commands => aoc/src/year2022}/day024.rs | 0 {src/cli/commands => aoc/src/year2022}/day025.rs | 0 {src/cli/commands => aoc/src/year2022}/mod.rs | 0 aoc22-clap/Cargo.toml | 9 +++++++++ {src => aoc22-clap/src}/cli/mod.rs | 3 +-- {src => aoc22-clap/src}/main.rs | 1 - 34 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 aoc/Cargo.toml create mode 100644 aoc/src/lib.rs rename {src => aoc/src}/util.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day001.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day002.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day003.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day004.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day005.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day006.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day007.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day008.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day009.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day010.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day011.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day012.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day013.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day014.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day015.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day016.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day017.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day018.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day019.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day020.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day021.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day022.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day023.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day024.rs (100%) rename {src/cli/commands => aoc/src/year2022}/day025.rs (100%) rename {src/cli/commands => aoc/src/year2022}/mod.rs (100%) create mode 100644 aoc22-clap/Cargo.toml rename {src => aoc22-clap/src}/cli/mod.rs (98%) rename {src => aoc22-clap/src}/main.rs (82%) diff --git a/Cargo.lock b/Cargo.lock index 1990bf4..12577c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,9 +3,14 @@ version = 3 [[package]] -name = "adventofcode2022" +name = "aoc" +version = "2022.1.0" + +[[package]] +name = "aoc22-clap" version = "2022.1.0" dependencies = [ + "aoc", "clap", ] @@ -118,9 +123,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.137" +version = "0.2.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" +checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" [[package]] name = "linux-raw-sys" @@ -184,9 +189,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.36.4" +version = "0.36.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb93e85278e08bb5788653183213d3a60fc242b10cb9be96586f5a73dcb67c23" +checksum = "a3807b5d10909833d3e9acd1eb5fb988f79376ff10fce42937de71a449c4c588" dependencies = [ "bitflags", "errno", diff --git a/Cargo.toml b/Cargo.toml index 4de8ea2..482001c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,6 @@ -[package] -name = "adventofcode2022" -version = "2022.1.0" -edition = "2021" +[workspace] - -[dependencies] -clap = { version = "4.0.29", features = ["derive"] } +members = [ +"aoc22-clap", +"aoc" +] \ No newline at end of file diff --git a/aoc/Cargo.toml b/aoc/Cargo.toml new file mode 100644 index 0000000..8739003 --- /dev/null +++ b/aoc/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "aoc" +version = "2022.1.0" +edition = "2021" + +[dependencies] diff --git a/aoc/src/lib.rs b/aoc/src/lib.rs new file mode 100644 index 0000000..cd57476 --- /dev/null +++ b/aoc/src/lib.rs @@ -0,0 +1,4 @@ +pub mod year2022; +pub mod util; + +pub use year2022::*; diff --git a/src/util.rs b/aoc/src/util.rs similarity index 100% rename from src/util.rs rename to aoc/src/util.rs diff --git a/src/cli/commands/day001.rs b/aoc/src/year2022/day001.rs similarity index 100% rename from src/cli/commands/day001.rs rename to aoc/src/year2022/day001.rs diff --git a/src/cli/commands/day002.rs b/aoc/src/year2022/day002.rs similarity index 100% rename from src/cli/commands/day002.rs rename to aoc/src/year2022/day002.rs diff --git a/src/cli/commands/day003.rs b/aoc/src/year2022/day003.rs similarity index 100% rename from src/cli/commands/day003.rs rename to aoc/src/year2022/day003.rs diff --git a/src/cli/commands/day004.rs b/aoc/src/year2022/day004.rs similarity index 100% rename from src/cli/commands/day004.rs rename to aoc/src/year2022/day004.rs diff --git a/src/cli/commands/day005.rs b/aoc/src/year2022/day005.rs similarity index 100% rename from src/cli/commands/day005.rs rename to aoc/src/year2022/day005.rs diff --git a/src/cli/commands/day006.rs b/aoc/src/year2022/day006.rs similarity index 100% rename from src/cli/commands/day006.rs rename to aoc/src/year2022/day006.rs diff --git a/src/cli/commands/day007.rs b/aoc/src/year2022/day007.rs similarity index 100% rename from src/cli/commands/day007.rs rename to aoc/src/year2022/day007.rs diff --git a/src/cli/commands/day008.rs b/aoc/src/year2022/day008.rs similarity index 100% rename from src/cli/commands/day008.rs rename to aoc/src/year2022/day008.rs diff --git a/src/cli/commands/day009.rs b/aoc/src/year2022/day009.rs similarity index 100% rename from src/cli/commands/day009.rs rename to aoc/src/year2022/day009.rs diff --git a/src/cli/commands/day010.rs b/aoc/src/year2022/day010.rs similarity index 100% rename from src/cli/commands/day010.rs rename to aoc/src/year2022/day010.rs diff --git a/src/cli/commands/day011.rs b/aoc/src/year2022/day011.rs similarity index 100% rename from src/cli/commands/day011.rs rename to aoc/src/year2022/day011.rs diff --git a/src/cli/commands/day012.rs b/aoc/src/year2022/day012.rs similarity index 100% rename from src/cli/commands/day012.rs rename to aoc/src/year2022/day012.rs diff --git a/src/cli/commands/day013.rs b/aoc/src/year2022/day013.rs similarity index 100% rename from src/cli/commands/day013.rs rename to aoc/src/year2022/day013.rs diff --git a/src/cli/commands/day014.rs b/aoc/src/year2022/day014.rs similarity index 100% rename from src/cli/commands/day014.rs rename to aoc/src/year2022/day014.rs diff --git a/src/cli/commands/day015.rs b/aoc/src/year2022/day015.rs similarity index 100% rename from src/cli/commands/day015.rs rename to aoc/src/year2022/day015.rs diff --git a/src/cli/commands/day016.rs b/aoc/src/year2022/day016.rs similarity index 100% rename from src/cli/commands/day016.rs rename to aoc/src/year2022/day016.rs diff --git a/src/cli/commands/day017.rs b/aoc/src/year2022/day017.rs similarity index 100% rename from src/cli/commands/day017.rs rename to aoc/src/year2022/day017.rs diff --git a/src/cli/commands/day018.rs b/aoc/src/year2022/day018.rs similarity index 100% rename from src/cli/commands/day018.rs rename to aoc/src/year2022/day018.rs diff --git a/src/cli/commands/day019.rs b/aoc/src/year2022/day019.rs similarity index 100% rename from src/cli/commands/day019.rs rename to aoc/src/year2022/day019.rs diff --git a/src/cli/commands/day020.rs b/aoc/src/year2022/day020.rs similarity index 100% rename from src/cli/commands/day020.rs rename to aoc/src/year2022/day020.rs diff --git a/src/cli/commands/day021.rs b/aoc/src/year2022/day021.rs similarity index 100% rename from src/cli/commands/day021.rs rename to aoc/src/year2022/day021.rs diff --git a/src/cli/commands/day022.rs b/aoc/src/year2022/day022.rs similarity index 100% rename from src/cli/commands/day022.rs rename to aoc/src/year2022/day022.rs diff --git a/src/cli/commands/day023.rs b/aoc/src/year2022/day023.rs similarity index 100% rename from src/cli/commands/day023.rs rename to aoc/src/year2022/day023.rs diff --git a/src/cli/commands/day024.rs b/aoc/src/year2022/day024.rs similarity index 100% rename from src/cli/commands/day024.rs rename to aoc/src/year2022/day024.rs diff --git a/src/cli/commands/day025.rs b/aoc/src/year2022/day025.rs similarity index 100% rename from src/cli/commands/day025.rs rename to aoc/src/year2022/day025.rs diff --git a/src/cli/commands/mod.rs b/aoc/src/year2022/mod.rs similarity index 100% rename from src/cli/commands/mod.rs rename to aoc/src/year2022/mod.rs diff --git a/aoc22-clap/Cargo.toml b/aoc22-clap/Cargo.toml new file mode 100644 index 0000000..19afcd9 --- /dev/null +++ b/aoc22-clap/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aoc22-clap" +version = "2022.1.0" +edition = "2021" + + +[dependencies] +clap = { version = "4.0.29", features = ["derive"] } +aoc = {path= "../aoc"} \ No newline at end of file diff --git a/src/cli/mod.rs b/aoc22-clap/src/cli/mod.rs similarity index 98% rename from src/cli/mod.rs rename to aoc22-clap/src/cli/mod.rs index a506aca..462e509 100644 --- a/src/cli/mod.rs +++ b/aoc22-clap/src/cli/mod.rs @@ -1,6 +1,5 @@ -mod commands; use clap::{arg, Parser, Subcommand}; -use commands::*; +use aoc::*; //use std::ffi::OsString; use std::path::PathBuf; diff --git a/src/main.rs b/aoc22-clap/src/main.rs similarity index 82% rename from src/main.rs rename to aoc22-clap/src/main.rs index 634bff3..11d70e6 100644 --- a/src/main.rs +++ b/aoc22-clap/src/main.rs @@ -1,4 +1,3 @@ -pub mod util; mod cli; use cli::execute_cli; From 289a06a228edb297469c4893994a641af438162a Mon Sep 17 00:00:00 2001 From: Leo Drachenfeuer Date: Tue, 13 Dec 2022 12:32:36 +0100 Subject: [PATCH 3/9] test around with multi bin projects --- Cargo.lock | 12 +++++ Cargo.toml | 18 +++++++- aoc22-clap/Cargo.toml | 3 +- aoc22-gdrop/Cargo.toml | 8 ++++ aoc22-gdrop/src/cli/mod.rs | 93 ++++++++++++++++++++++++++++++++++++++ aoc22-gdrop/src/main.rs | 7 +++ 6 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 aoc22-gdrop/Cargo.toml create mode 100644 aoc22-gdrop/src/cli/mod.rs create mode 100644 aoc22-gdrop/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 12577c3..2d1938a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,10 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "adventofcode" +version = "2022.1.0" + [[package]] name = "aoc" version = "2022.1.0" @@ -14,6 +18,14 @@ dependencies = [ "clap", ] +[[package]] +name = "aoc22-gdrop" +version = "2022.1.0" +dependencies = [ + "aoc", + "clap", +] + [[package]] name = "bitflags" version = "1.3.2" diff --git a/Cargo.toml b/Cargo.toml index 482001c..398943c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,20 @@ -[workspace] +[package] +name = "adventofcode" +version = "2022.1.0" +edition = "2021" + +[workspace] members = [ "aoc22-clap", +"aoc22-gdrop", "aoc" -] \ No newline at end of file +] + +[[bin]] +name = "aoc22-clap" +path = "aoc22-clap" + +[[bin]] +name = "aoc22-gdrop" +path = "aoc22-gdrop" \ No newline at end of file diff --git a/aoc22-clap/Cargo.toml b/aoc22-clap/Cargo.toml index 19afcd9..820019c 100644 --- a/aoc22-clap/Cargo.toml +++ b/aoc22-clap/Cargo.toml @@ -3,7 +3,6 @@ name = "aoc22-clap" version = "2022.1.0" edition = "2021" - [dependencies] clap = { version = "4.0.29", features = ["derive"] } -aoc = {path= "../aoc"} \ No newline at end of file +aoc = {path= "../aoc"} diff --git a/aoc22-gdrop/Cargo.toml b/aoc22-gdrop/Cargo.toml new file mode 100644 index 0000000..2219dee --- /dev/null +++ b/aoc22-gdrop/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "aoc22-gdrop" +version = "2022.1.0" +edition = "2021" + +[dependencies] +clap = { version = "4.0.29", features = ["derive"] } +aoc = {path= "../aoc"} diff --git a/aoc22-gdrop/src/cli/mod.rs b/aoc22-gdrop/src/cli/mod.rs new file mode 100644 index 0000000..462e509 --- /dev/null +++ b/aoc22-gdrop/src/cli/mod.rs @@ -0,0 +1,93 @@ +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, + /// 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, + #[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, + #[arg(long)] + alt: bool, + }, + /// Solution for day 04 + Day004 { + file: Option, + #[arg(long)] + alt: bool, + }, + /// Solution for day 05 + Day005 { + file: Option, + #[arg(long)] + alt: bool, + }, + /// Solution for day 06 + Day006 { + file: Option, + #[arg(long)] + alt: bool, + }, + /// Solution for day 07 + Day007 { + file: Option, + #[arg(long)] + alt: bool, + }, + /// Solution for day 08 + Day008 { + file: Option, + #[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) + } +} diff --git a/aoc22-gdrop/src/main.rs b/aoc22-gdrop/src/main.rs new file mode 100644 index 0000000..11d70e6 --- /dev/null +++ b/aoc22-gdrop/src/main.rs @@ -0,0 +1,7 @@ +mod cli; + +use cli::execute_cli; + +fn main() { + execute_cli(); +} From 3f6d9223d5475128c7415c494066703c3b75fe5b Mon Sep 17 00:00:00 2001 From: Leo Drachenfeuer Date: Mon, 19 Dec 2022 08:13:44 +0100 Subject: [PATCH 4/9] add first draft of a gumdrop implementation --- Cargo.lock | 26 +++++-- Cargo.toml | 14 ---- aoc22-gdrop/Cargo.toml | 2 +- aoc22-gdrop/src/cli/mod.rs | 145 ++++++++++++++++++------------------- 4 files changed, 93 insertions(+), 94 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d1938a..5d8c3d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 398943c..7c203f6 100644 --- a/Cargo.toml +++ b/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" \ No newline at end of file diff --git a/aoc22-gdrop/Cargo.toml b/aoc22-gdrop/Cargo.toml index 2219dee..6443bc8 100644 --- a/aoc22-gdrop/Cargo.toml +++ b/aoc22-gdrop/Cargo.toml @@ -4,5 +4,5 @@ version = "2022.1.0" edition = "2021" [dependencies] -clap = { version = "4.0.29", features = ["derive"] } +gumdrop = "0.8" aoc = {path= "../aoc"} diff --git a/aoc22-gdrop/src/cli/mod.rs b/aoc22-gdrop/src/cli/mod.rs index 462e509..6a87d2f 100644 --- a/aoc22-gdrop/src/cli/mod.rs +++ b/aoc22-gdrop/src/cli/mod.rs @@ -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, } -#[derive(Subcommand)] +#[derive(Debug, Options)] pub enum Commands { - /// Solution for the first day - Day001 { - file: Option, - /// 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, - #[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, - #[arg(long)] - alt: bool, - }, - /// Solution for day 04 - Day004 { - file: Option, - #[arg(long)] - alt: bool, - }, - /// Solution for day 05 - Day005 { - file: Option, - #[arg(long)] - alt: bool, - }, - /// Solution for day 06 - Day006 { - file: Option, - #[arg(long)] - alt: bool, - }, - /// Solution for day 07 - Day007 { - file: Option, - #[arg(long)] - alt: bool, - }, - /// Solution for day 08 - Day008 { - file: Option, - #[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, + #[options(help = "use alternative subfunction for part2")] + alt: bool, +} + +#[derive(Debug, Options)] +pub struct BasicOptions2 { + #[options(free, help = "file with input data")] + file: Option, + #[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, + #[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!(), } } From 365061837c3ad7f8b688a418cc556ca50d6568c4 Mon Sep 17 00:00:00 2001 From: Leo Drachenfeuer Date: Mon, 19 Dec 2022 08:14:29 +0100 Subject: [PATCH 5/9] set default binary --- aoc22-clap/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/aoc22-clap/Cargo.toml b/aoc22-clap/Cargo.toml index 820019c..0c2c1ee 100644 --- a/aoc22-clap/Cargo.toml +++ b/aoc22-clap/Cargo.toml @@ -2,6 +2,7 @@ name = "aoc22-clap" version = "2022.1.0" edition = "2021" +default-run = "aoc22-clap" [dependencies] clap = { version = "4.0.29", features = ["derive"] } From 31730ed6cd11cbdc456637280308a418ce2bfc1b Mon Sep 17 00:00:00 2001 From: Leo Drachenfeuer Date: Mon, 19 Dec 2022 09:21:39 +0100 Subject: [PATCH 6/9] change version number --- Cargo.lock | 30 +++++++++++++++--------------- aoc/Cargo.toml | 3 ++- aoc22-clap/Cargo.toml | 3 ++- aoc22-gdrop/Cargo.toml | 3 ++- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d8c3d1..9b8c40c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,11 +4,11 @@ version = 3 [[package]] name = "aoc" -version = "2022.1.0" +version = "0.0.1" [[package]] name = "aoc22-clap" -version = "2022.1.0" +version = "0.0.1" dependencies = [ "aoc", "clap", @@ -16,7 +16,7 @@ dependencies = [ [[package]] name = "aoc22-gdrop" -version = "2022.1.0" +version = "0.0.1" dependencies = [ "aoc", "gumdrop", @@ -30,9 +30,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cc" -version = "1.0.77" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" [[package]] name = "clap" @@ -157,9 +157,9 @@ checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" [[package]] name = "linux-raw-sys" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "once_cell" @@ -199,18 +199,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.47" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ "proc-macro2", ] @@ -237,9 +237,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.105" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ "proc-macro2", "quote", @@ -257,9 +257,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "version_check" diff --git a/aoc/Cargo.toml b/aoc/Cargo.toml index 8739003..9330341 100644 --- a/aoc/Cargo.toml +++ b/aoc/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "aoc" -version = "2022.1.0" +version = "0.0.1" edition = "2021" +authors = ["Leo Drachenfeuer "] [dependencies] diff --git a/aoc22-clap/Cargo.toml b/aoc22-clap/Cargo.toml index 0c2c1ee..142052b 100644 --- a/aoc22-clap/Cargo.toml +++ b/aoc22-clap/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "aoc22-clap" -version = "2022.1.0" +version = "0.0.1" edition = "2021" +authors = ["Leo Drachenfeuer "] default-run = "aoc22-clap" [dependencies] diff --git a/aoc22-gdrop/Cargo.toml b/aoc22-gdrop/Cargo.toml index 6443bc8..2cf8611 100644 --- a/aoc22-gdrop/Cargo.toml +++ b/aoc22-gdrop/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "aoc22-gdrop" -version = "2022.1.0" +version = "0.0.1" edition = "2021" +authors = ["Leo Drachenfeuer "] [dependencies] gumdrop = "0.8" From 4af705f372fdf1b11f1344e5b9733567493406fa Mon Sep 17 00:00:00 2001 From: Leo Drachenfeuer Date: Mon, 19 Dec 2022 09:24:12 +0100 Subject: [PATCH 7/9] for testing output given arguments --- aoc22-clap/src/main.rs | 4 ++++ aoc22-gdrop/src/main.rs | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/aoc22-clap/src/main.rs b/aoc22-clap/src/main.rs index 11d70e6..2c5be02 100644 --- a/aoc22-clap/src/main.rs +++ b/aoc22-clap/src/main.rs @@ -1,7 +1,11 @@ mod cli; +use std::env; use cli::execute_cli; fn main() { execute_cli(); + for argument in env::args() { + println!("{argument}"); + } } diff --git a/aoc22-gdrop/src/main.rs b/aoc22-gdrop/src/main.rs index 11d70e6..7311e21 100644 --- a/aoc22-gdrop/src/main.rs +++ b/aoc22-gdrop/src/main.rs @@ -1,7 +1,10 @@ mod cli; - +use std::env; use cli::execute_cli; fn main() { execute_cli(); + for argument in env::args() { + println!("{argument}"); + } } From b6147ca7f2753752f483b55262d2d25937555de7 Mon Sep 17 00:00:00 2001 From: Leo Drachenfeuer Date: Mon, 19 Dec 2022 09:25:54 +0100 Subject: [PATCH 8/9] rename the clap based version to aoc22 only --- {aoc22-clap => aoc22}/Cargo.toml | 4 ++-- {aoc22-clap => aoc22}/src/cli/mod.rs | 0 {aoc22-clap => aoc22}/src/main.rs | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename {aoc22-clap => aoc22}/Cargo.toml (80%) rename {aoc22-clap => aoc22}/src/cli/mod.rs (100%) rename {aoc22-clap => aoc22}/src/main.rs (100%) diff --git a/aoc22-clap/Cargo.toml b/aoc22/Cargo.toml similarity index 80% rename from aoc22-clap/Cargo.toml rename to aoc22/Cargo.toml index 142052b..852dab8 100644 --- a/aoc22-clap/Cargo.toml +++ b/aoc22/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = "aoc22-clap" +name = "aoc22" version = "0.0.1" edition = "2021" authors = ["Leo Drachenfeuer "] -default-run = "aoc22-clap" +default-run = "aoc22" [dependencies] clap = { version = "4.0.29", features = ["derive"] } diff --git a/aoc22-clap/src/cli/mod.rs b/aoc22/src/cli/mod.rs similarity index 100% rename from aoc22-clap/src/cli/mod.rs rename to aoc22/src/cli/mod.rs diff --git a/aoc22-clap/src/main.rs b/aoc22/src/main.rs similarity index 100% rename from aoc22-clap/src/main.rs rename to aoc22/src/main.rs From 9e56cc9f25ca95113c000c6b41e3444a72df17be Mon Sep 17 00:00:00 2001 From: Leo Drachenfeuer Date: Thu, 26 Jan 2023 17:40:26 +0100 Subject: [PATCH 9/9] optimize cargo settings --- Cargo.lock | 2 +- Cargo.toml | 2 +- notes.md | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 notes.md diff --git a/Cargo.lock b/Cargo.lock index 9b8c40c..65f282d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,7 +7,7 @@ name = "aoc" version = "0.0.1" [[package]] -name = "aoc22-clap" +name = "aoc22" version = "0.0.1" dependencies = [ "aoc", diff --git a/Cargo.toml b/Cargo.toml index 7c203f6..90b96af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] members = [ -"aoc22-clap", +"aoc22", "aoc22-gdrop", "aoc" ] diff --git a/notes.md b/notes.md new file mode 100644 index 0000000..1e2e506 --- /dev/null +++ b/notes.md @@ -0,0 +1,2 @@ +clap is the best availiable arg parser at the moment for rust but clap comes with the tradeoff of a size overhead for the executalble. +The overhead is around 550kb \ No newline at end of file