feat: add help

This commit is contained in:
2022-08-06 02:11:24 +08:00
parent 9c8d0acd25
commit 60283c7b40

View File

@@ -1,7 +1,9 @@
#[macro_use] #[macro_use]
extern crate rust_util; extern crate rust_util;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::Command; use std::process::Command;
fn main() { fn main() {
let home = std::env::var("HOME").unwrap_or_else(|_| let home = std::env::var("HOME").unwrap_or_else(|_|
failure_and_exit!("$HOME not found!") failure_and_exit!("$HOME not found!")
@@ -20,12 +22,33 @@ fn main() {
} }
let args = std::env::args().skip(1).collect::<Vec<_>>(); let args = std::env::args().skip(1).collect::<Vec<_>>();
if args.is_empty() { if args.is_empty() {
failure_and_exit!("runrs need arguments, e.g.\n\nrunrs <scirpt.ers> [arguments]\n"); failure_and_exit!(
"runrs v{}, need arguments, e.g.\n\nrunrs <script.rs> [arguments]\n",
env!("CARGO_PKG_VERSION"),
);
} }
let script_file = match args.get(0) { let first_argument = match args.get(0) {
None => failure_and_exit!("Must assign file name"), None => failure_and_exit!("Must assign file name"),
Some(f) => f, Some(f) => f,
}; };
if first_argument == "--help" {
println!(r##"{} v{} - {}
Help:
runrs --help
Run Rust Script:
runrs <script.rs> [arguments]
"##,
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
env!("CARGO_PKG_DESCRIPTION")
);
return;
}
let script_file = first_argument;
let script_content = match std::fs::read_to_string(script_file) { let script_content = match std::fs::read_to_string(script_file) {
Err(e) => failure_and_exit!("Read file: {}, failed: {}", script_file, e), Err(e) => failure_and_exit!("Read file: {}, failed: {}", script_file, e),
Ok(c) => c, Ok(c) => c,