Skip to content

Commit de19b28

Browse files
committed
Add README, update usage, add (unused) logo :)
1 parent 23b68af commit de19b28

File tree

3 files changed

+62
-9
lines changed

3 files changed

+62
-9
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# AdventOfCode 2021 - Learning Rust :heart: again ^^
2+
3+
This is my take on the [advent of code challenges](https://adventofcode.com/2021/) of 2021.
4+
5+
I already tried doing them in Rust [last year](https://github.com/bew/adventofcode-2020), but didn't go too far, because (for learning
6+
purpose) I wanted to not use any libs, so I learned about cumbersome parsing and having to
7+
re-write a simple generic error wrapper :)
8+
9+
Now I want to actually do somthing in Rust, so I'm using a few libraries, mainly:
10+
- [`anyhow`](https://crates.io/crates/anyhow) for error wrapping, without having to deal with specific errors
11+
- [`chumsky`](https://crates.io/crates/chumsky) for input parsing using combinators that build incrementally the AST of the input :heart:. I discovered this lib not long ago, and I fell in love, it's time to try it _for real_ now!
12+
13+
14+
## Workflow
15+
16+
* `cargo run last`: Run the last available day, display results.
17+
It's very handy when I'm working on the next day :smiley:
18+
19+
* `cargo run all`: Run all days, display results
20+
21+
* `cargo run list`: List available days
22+
23+
* `cargo run dayNN`: Run specific day

logo.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
| ___ ___ ___ __ ___ _ |
2+
| o O O / \ ___ / __| |_ ) / \ |_ ) / | |
3+
| o | - | / _ \ | (__ / / | () | / / | | |
4+
| TS__[O] |_|_| \___/ \___| /___| _\__/ /___| _|_|_ |
5+
| {======|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|
6+
| ./o--000'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"|
7+
| |
8+
| _ ___ _ |
9+
| (_) _ _ | _ \ _ _ ___ | |_ O O o |
10+
| | | | ' \ | / | \| | (_-< | _| o |
11+
| _|_|_ |_||_| _____ |_|_\ \_,_| /__/_ _\__| [O]__ST |
12+
|_|"""""|_|"""""|_| |_|"""""|_|"""""|_|"""""|_|"""""|_|======} |
13+
|"`-0-0-'"`-0-0-'"'-0-0-`"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"'000--o\. |

src/main.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,20 @@ static DAYS: &[Day] = &[
5454
fn print_usage() {
5555
let prog_name = env::args().next().unwrap_or("prog".to_string());
5656
let day_names: Vec<_> = DAYS.iter().map(|d| d.name).collect();
57-
println!("Usage: {} <day> [<custom_input_path>]", prog_name);
58-
println!(
59-
"Where <day> is either 'all', 'last' or one of: {}",
60-
day_names.join(", ")
61-
);
57+
println!("Usage:");
58+
println!(" {} <cmd>", prog_name);
59+
println!(" {} <day> [<custom_input_path>]", prog_name);
60+
println!("");
61+
62+
println!("<cmd> can be:");
63+
println!(" all - run all available days");
64+
println!(" last - run the last available day (used while dev)");
65+
println!(" list - list available days");
66+
println!("");
67+
68+
let joined_days = day_names.join(", ");
69+
println!("<day> can be one of: {}", joined_days);
70+
println!("");
6271
exit(1);
6372
}
6473

@@ -92,10 +101,10 @@ fn main() -> anyhow::Result<()> {
92101
// TODO: Use clap to parse params to structured opts!
93102
let prog_args: Vec<String> = env::args().collect();
94103
let first_arg = prog_args.get(1);
95-
// Converts Option<String> to Option<&str> so I can match on `Some("all")`
96-
// (necessary because matching on `Some("all".to_string())` does not work
97-
// and matching on `Some(xyz) if xyz == "all"` is ugly..).
98-
match first_arg.and_then(|s| Some(s.as_str())) {
104+
105+
// NOTE: We convert Option<String> to Option<&str> to be able to match on `Some("all")`,
106+
// instead of matching `Some(xyz) if xyz == "all"` many times, which is quite ugly.
107+
match first_arg.map(String::as_str) {
99108
Some("all") => {
100109
for day in DAYS {
101110
run_day(day)?;
@@ -104,6 +113,14 @@ fn main() -> anyhow::Result<()> {
104113
Some("last") => {
105114
run_day(&DAYS.last().unwrap())?;
106115
}
116+
Some("list") => {
117+
println!("Available days:");
118+
for day in DAYS {
119+
println!("- {}", day.name);
120+
// TODO: Display how finish that day it, by running it without displaying anything
121+
// (need to return proper enum with all statuses)
122+
}
123+
}
107124
Some(wanted_day) => {
108125
let matching_day = DAYS.iter().find(|day| day.name == wanted_day);
109126
match matching_day {

0 commit comments

Comments
 (0)