feat: init commit

This commit is contained in:
2021-07-24 01:50:11 +08:00
parent 531aae29dd
commit 70f202e982
4 changed files with 198 additions and 2 deletions

View File

@@ -1,3 +1,50 @@
#[macro_use]
extern crate rust_util;
use std::process::Command;
use std::path::PathBuf;
fn main() {
println!("Hello, world!");
let home = std::env::var("HOME").unwrap_or_else(|_|
failure_and_exit!("$HOME not found!")
);
let rust_script = PathBuf::from(format!("{}/.cargo/bin/rust-script", home));
if !rust_script.exists() {
warning!("rust-script not found, install it...");
let mut cargo_install_rust_script = Command::new("cargo");
cargo_install_rust_script.args(&["install", "rust-script"]);
debugging!("Run command: {:?}", cargo_install_rust_script);
let run_result = rust_util::util_cmd::run_command_and_wait(&mut cargo_install_rust_script);
if let Err(e) = run_result {
failure_and_exit!("Install rust-script failed: {}", e);
}
}
let mut copied_args = vec![];
std::env::args().skip(1).for_each(|arg| {
copied_args.push(arg);
});
debugging!("Arguments: {:?}", copied_args);
if copied_args.is_empty() {
failure_and_exit!("Run `runrs --help` for help.");
}
if let Some(arg1) = copied_args.get(0) {
match arg1.as_str() {
":::" => {
// TODO
}
_ => {} // IGNORE
}
}
let mut run_rs = Command::new(rust_script);
for arg in &copied_args {
run_rs.arg(arg);
}
debugging!("Run command: {:?}", run_rs);
if let Err(e) = rust_util::util_cmd::run_command_and_wait(&mut run_rs) {
failure_and_exit!("Run rust-script failed: {}", e);
}
}