commit 5356a04e842eb1de98de39562d992ce1f50480d7 Author: J / Jacob Babich Date: Sat Nov 18 13:18:05 2023 -0500 🚀 meta: initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..25a160d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,16 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "dotenv" +version = "0.1.0" +dependencies = [ + "dotenvy", +] + +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e13f0a9 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "dotenv" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dotenvy = "0.15.7" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..0d041ab --- /dev/null +++ b/src/main.rs @@ -0,0 +1,35 @@ +use std::process::{exit, Command}; + +fn main() -> Result<(), std::io::Error> { + dotenvy::dotenv().unwrap(); + + let mut args = std::env::args_os(); + + let _dotenv = args.next(); + + let first = args.next().ok_or(std::io::Error::other( + "pass a command and args after dotenv when running the program", + ))?; + + let mut command = Command::new(first); + + for arg in args { + command.arg(arg); + } + + let mut child = command.spawn()?; + + let exit_status = child.wait()?; + match exit_status.code() { + Some(code) => exit(code), + None => { + if exit_status.success() { + Ok(()) + } else { + Err(std::io::Error::other( + "program exited unsuccessfully without a code", + )) + } + } + } +}