🚀 meta: initial commit
This commit is contained in:
35
src/main.rs
Normal file
35
src/main.rs
Normal file
@@ -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",
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user