diff --git a/Cargo.lock b/Cargo.lock index 1990bf4..65f282d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,12 +3,25 @@ version = 3 [[package]] -name = "adventofcode2022" -version = "2022.1.0" +name = "aoc" +version = "0.0.1" + +[[package]] +name = "aoc22" +version = "0.0.1" dependencies = [ + "aoc", "clap", ] +[[package]] +name = "aoc22-gdrop" +version = "0.0.1" +dependencies = [ + "aoc", + "gumdrop", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -17,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" @@ -79,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" @@ -118,15 +151,15 @@ 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" -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" @@ -166,27 +199,27 @@ 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", ] [[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", @@ -204,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", @@ -224,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/Cargo.toml b/Cargo.toml index 4de8ea2..90b96af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,6 @@ -[package] -name = "adventofcode2022" -version = "2022.1.0" -edition = "2021" - - -[dependencies] -clap = { version = "4.0.29", features = ["derive"] } +[workspace] +members = [ +"aoc22", +"aoc22-gdrop", +"aoc" +] diff --git a/aoc/Cargo.toml b/aoc/Cargo.toml new file mode 100644 index 0000000..9330341 --- /dev/null +++ b/aoc/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "aoc" +version = "0.0.1" +edition = "2021" +authors = ["Leo Drachenfeuer "] + +[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/aoc/src/year2022/mod.rs b/aoc/src/year2022/mod.rs new file mode 100644 index 0000000..e73cfd1 --- /dev/null +++ b/aoc/src/year2022/mod.rs @@ -0,0 +1,35 @@ +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/aoc22-gdrop/Cargo.toml b/aoc22-gdrop/Cargo.toml new file mode 100644 index 0000000..2cf8611 --- /dev/null +++ b/aoc22-gdrop/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aoc22-gdrop" +version = "0.0.1" +edition = "2021" +authors = ["Leo Drachenfeuer "] + +[dependencies] +gumdrop = "0.8" +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..6a87d2f --- /dev/null +++ b/aoc22-gdrop/src/cli/mod.rs @@ -0,0 +1,90 @@ +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, +} + +#[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, + #[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_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!(), + } +} diff --git a/aoc22-gdrop/src/main.rs b/aoc22-gdrop/src/main.rs new file mode 100644 index 0000000..7311e21 --- /dev/null +++ b/aoc22-gdrop/src/main.rs @@ -0,0 +1,10 @@ +mod cli; +use std::env; +use cli::execute_cli; + +fn main() { + execute_cli(); + for argument in env::args() { + println!("{argument}"); + } +} diff --git a/aoc22/Cargo.toml b/aoc22/Cargo.toml new file mode 100644 index 0000000..852dab8 --- /dev/null +++ b/aoc22/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "aoc22" +version = "0.0.1" +edition = "2021" +authors = ["Leo Drachenfeuer "] +default-run = "aoc22" + +[dependencies] +clap = { version = "4.0.29", features = ["derive"] } +aoc = {path= "../aoc"} diff --git a/src/cli/mod.rs b/aoc22/src/cli/mod.rs similarity index 92% rename from src/cli/mod.rs rename to aoc22/src/cli/mod.rs index be32135..462e509 100644 --- a/src/cli/mod.rs +++ b/aoc22/src/cli/mod.rs @@ -1,13 +1,5 @@ -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 aoc::*; //use std::ffi::OsString; use std::path::PathBuf; diff --git a/aoc22/src/main.rs b/aoc22/src/main.rs new file mode 100644 index 0000000..2c5be02 --- /dev/null +++ b/aoc22/src/main.rs @@ -0,0 +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/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 diff --git a/src/cli/commands/mod.rs b/src/cli/commands/mod.rs deleted file mode 100644 index 080c1c0..0000000 --- a/src/cli/commands/mod.rs +++ /dev/null @@ -1,25 +0,0 @@ -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; diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 634bff3..0000000 --- a/src/main.rs +++ /dev/null @@ -1,8 +0,0 @@ -pub mod util; -mod cli; - -use cli::execute_cli; - -fn main() { - execute_cli(); -}