]> aoc.elinar.fr Git - aoc_2024/commitdiff
Commit initial comportant le main
authoralex <>
Sun, 1 Dec 2024 16:53:12 +0000 (17:53 +0100)
committeralex <>
Sun, 1 Dec 2024 16:53:12 +0000 (17:53 +0100)
.gitignore [new file with mode: 0644]
Cargo.toml [new file with mode: 0644]
src/main.rs [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..05cc302
--- /dev/null
@@ -0,0 +1,4 @@
+Cargo.lock
+/target
+
+*.sw*
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644 (file)
index 0000000..74b5bcc
--- /dev/null
@@ -0,0 +1,6 @@
+[package]
+name = "aoc_2024"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/main.rs b/src/main.rs
new file mode 100644 (file)
index 0000000..b838528
--- /dev/null
@@ -0,0 +1,31 @@
+use std::env;
+use std::process;
+use std::error::Error;
+use std::fs::File;
+use std::io::Read;
+
+fn main() {
+    let args: Vec<String> = env::args().collect();
+    if args.len() != 3 {
+        let exe_name = args[0].split('/').last().unwrap();
+        println!("Missing argument");
+        println!("usage: {} <DAY> <INPUT_FILE>", exe_name);
+        process::exit(1);
+    }
+
+    if let Err(e) = run(&args[1], &args[2]) {
+        println!("Error: {e}");
+        process::exit(2);
+    }
+}
+
+fn run(day: &str, input_file: &str) -> Result<(), Box<dyn Error>> {
+    let mut f = File::open(input_file)?;
+    let mut input = String::new();
+    f.read_to_string(&mut input)?;
+
+    match day {
+        _ => return Err(format!("unknown or unimplemented day \"{day}\"").into()),
+    }
+    Ok(())
+}