feat: v0.1.12

This commit is contained in:
2023-02-10 23:44:45 +08:00
parent 38ab32052d
commit a8eb20dbb1
4 changed files with 57 additions and 5 deletions

View File

@@ -8,19 +8,26 @@ use std::time::SystemTime;
use rust_util::util_cmd;
const SCRIPT_TEMPLATE: &'static str = include_str!("script.template");
fn main() {
let user_home = get_user_home();
let rust_script = get_run_script_bin_name(&user_home);
let args = env::args().skip(1).collect::<Vec<_>>();
if args.is_empty() {
failure_and_exit!("runrs v{}, need arguments, e.g.\n\nrunrs <script.rs> [arguments]\n", env!("CARGO_PKG_VERSION"));
failure_and_exit!("runrs v{}, need arguments, `runrs --help` for help", env!("CARGO_PKG_VERSION"));
}
let first_argument = args.get(0).unwrap_or_else(|| failure_and_exit!("Must assign a script file name"));
if first_argument == "--help" {
if first_argument == "--help" || first_argument == "-h" {
print_help();
return;
}
if first_argument == "--template" || first_argument == "-t" {
println!("{}", SCRIPT_TEMPLATE);
return;
}
let script_file = first_argument;
let (_, script_sha256) = read_file_and_digest(script_file);
@@ -89,10 +96,23 @@ fn print_help() {
println!(r##"{} v{} - {}
Help:
runrs --help
runrs -h|--help
Show template:
runrs -t|--template
Run Rust Script:
runrs <script.rs> [arguments]
Environment variables:
| Variable | Description |
| -------------------- | ------------------------------------------------------------ |
| HOME | User home, default by OS system |
| RUNRS_SKIP_CACHE | Skip compiled cached file, bool , turn on true, yes, on or 1 |
| RUNRS_REBUILD | Force rebuild, bool |
| RUNRS_SILENT_BUILD | Build new binary in silent mode, bool |
| RUNRS_RUST_SCRIPT | rust_script command line bin file |
| RUNRS_MAX_SCRIPT_LEN | Max script length, default 1MB |
"##,
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),