feat: v1.0.1, fix filter issue
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -927,7 +927,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "runrs"
|
name = "runrs"
|
||||||
version = "1.0.0"
|
version = "1.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argh",
|
"argh",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "runrs"
|
name = "runrs"
|
||||||
version = "1.0.0"
|
version = "1.0.1"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "A Tool for Run Rust Scripts"
|
description = "A Tool for Run Rust Scripts"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ pub fn print_help() {
|
|||||||
#[allow(unreachable_code)]
|
#[allow(unreachable_code)]
|
||||||
fn get_help() -> &'static str {
|
fn get_help() -> &'static str {
|
||||||
#[cfg(feature = "switch-rust-lang")]
|
#[cfg(feature = "switch-rust-lang")]
|
||||||
return include_str!("script.help.rust.txt");
|
return include_str!("script.help.rs.txt");
|
||||||
#[cfg(feature = "switch-go-lang")]
|
#[cfg(feature = "switch-go-lang")]
|
||||||
return include_str!("script.help.go.txt");
|
return include_str!("script.help.go.txt");
|
||||||
#[cfg(feature = "switch-ts-lang")]
|
#[cfg(feature = "switch-ts-lang")]
|
||||||
|
|||||||
62
src/main.rs
62
src/main.rs
@@ -2,17 +2,12 @@
|
|||||||
extern crate rust_util;
|
extern crate rust_util;
|
||||||
|
|
||||||
use argh::FromArgs;
|
use argh::FromArgs;
|
||||||
use rust_util::util_os::get_user_home;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use crate::list::list_scripts;
|
|
||||||
use crate::util::{
|
|
||||||
build_script_command, get_run_script_bin_name, read_file_and_digest, run_script_command,
|
|
||||||
};
|
|
||||||
|
|
||||||
mod help;
|
mod help;
|
||||||
mod install;
|
mod install;
|
||||||
mod list;
|
mod list;
|
||||||
|
mod run_rs;
|
||||||
mod template;
|
mod template;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
@@ -41,11 +36,9 @@ struct RunScriptArgs {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let rs_args: RunScriptArgs = argh::from_env();
|
let rs_args: RunScriptArgs = argh::from_env();
|
||||||
// println!("{:#?}", rs_args);
|
|
||||||
|
|
||||||
let cmd_name = util::get_cmd_name();
|
|
||||||
let cmd_version = env!("CARGO_PKG_VERSION");
|
let cmd_version = env!("CARGO_PKG_VERSION");
|
||||||
if env::args().len() == 1 {
|
if env::args().len() == 1 {
|
||||||
|
let cmd_name = util::get_cmd_name();
|
||||||
failure_and_exit!(
|
failure_and_exit!(
|
||||||
"{cmd_name} v{cmd_version}, need arguments, `{cmd_name} -h` or `{cmd_name} --help-message` for help"
|
"{cmd_name} v{cmd_version}, need arguments, `{cmd_name} -h` or `{cmd_name} --help-message` for help"
|
||||||
);
|
);
|
||||||
@@ -60,7 +53,7 @@ fn main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if rs_args.list {
|
if rs_args.list {
|
||||||
list_scripts(rs_args.arguments.get(1));
|
list::list_scripts(rs_args.arguments.get(0));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if rs_args.install {
|
if rs_args.install {
|
||||||
@@ -68,48 +61,15 @@ fn main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(
|
do_run_script(&rs_args);
|
||||||
feature = "switch-go-lang",
|
|
||||||
feature = "switch-ts-lang",
|
|
||||||
feature = "switch-dart-lang"
|
|
||||||
))]
|
|
||||||
if true {
|
|
||||||
failure_and_exit!("Only rust supports run by runrs.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if rs_args.arguments.is_empty() {
|
#[allow(unreachable_code)]
|
||||||
failure_and_exit!("Must assign a script file name");
|
fn do_run_script(rs_args: &RunScriptArgs) {
|
||||||
|
#[cfg(feature = "switch-rust-lang")]
|
||||||
|
{
|
||||||
|
run_rs::do_run_script(&rs_args);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
let script_file = &rs_args.arguments[0];
|
failure_and_exit!("Only rust script supported.");
|
||||||
let (_, script_sha256) = read_file_and_digest(script_file);
|
|
||||||
debugging!("File {} -> sha256: {}", script_file, script_sha256);
|
|
||||||
|
|
||||||
let user_home = get_user_home().unwrap_or_else(|| failure_and_exit!("$HOME not found!"));
|
|
||||||
let rust_script = get_run_script_bin_name(&user_home);
|
|
||||||
let cache_script_bin_name = get_cache_script_bin_name(&user_home, &script_sha256);
|
|
||||||
let mut run_script_cmd = build_script_command(
|
|
||||||
rust_script,
|
|
||||||
script_file,
|
|
||||||
&script_sha256,
|
|
||||||
&cache_script_bin_name,
|
|
||||||
);
|
|
||||||
for arg in rs_args.arguments.iter().skip(1) {
|
|
||||||
run_script_cmd.arg(arg);
|
|
||||||
}
|
|
||||||
run_script_command(script_file, &cache_script_bin_name, &mut run_script_cmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_cache_script_bin_name(user_home: &str, script_sha256: &str) -> String {
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
let cache_script_bin_name = format!(
|
|
||||||
"{}/Library/Caches/rust-script/binaries/release/{}",
|
|
||||||
user_home, script_sha256
|
|
||||||
);
|
|
||||||
// #[cfg(target_os = "linux")]
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
|
||||||
let cache_script_bin_name = format!(
|
|
||||||
"{}/.cache/rust-script/binaries/release/{}",
|
|
||||||
user_home, script_sha256
|
|
||||||
);
|
|
||||||
cache_script_bin_name
|
|
||||||
}
|
}
|
||||||
|
|||||||
40
src/run_rs.rs
Normal file
40
src/run_rs.rs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
use crate::{util, RunScriptArgs};
|
||||||
|
use rust_util::util_os::get_user_home;
|
||||||
|
|
||||||
|
pub fn do_run_script(rs_args: &RunScriptArgs) {
|
||||||
|
if rs_args.arguments.is_empty() {
|
||||||
|
failure_and_exit!("Must assign a script file name");
|
||||||
|
}
|
||||||
|
let script_file = &rs_args.arguments[0];
|
||||||
|
let (_, script_sha256) = util::read_file_and_digest(script_file);
|
||||||
|
debugging!("File {} -> sha256: {}", script_file, script_sha256);
|
||||||
|
|
||||||
|
let user_home = get_user_home().unwrap_or_else(|| failure_and_exit!("$HOME not found!"));
|
||||||
|
let rust_script = util::get_run_script_bin_name(&user_home);
|
||||||
|
let cache_script_bin_name = get_cache_script_bin_name(&user_home, &script_sha256);
|
||||||
|
let mut run_script_cmd = util::build_script_command(
|
||||||
|
rust_script,
|
||||||
|
script_file,
|
||||||
|
&script_sha256,
|
||||||
|
&cache_script_bin_name,
|
||||||
|
);
|
||||||
|
for arg in rs_args.arguments.iter().skip(1) {
|
||||||
|
run_script_cmd.arg(arg);
|
||||||
|
}
|
||||||
|
util::run_script_command(script_file, &cache_script_bin_name, &mut run_script_cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_cache_script_bin_name(user_home: &str, script_sha256: &str) -> String {
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
let cache_script_bin_name = format!(
|
||||||
|
"{}/Library/Caches/rust-script/binaries/release/{}",
|
||||||
|
user_home, script_sha256
|
||||||
|
);
|
||||||
|
// #[cfg(target_os = "linux")]
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
let cache_script_bin_name = format!(
|
||||||
|
"{}/.cache/rust-script/binaries/release/{}",
|
||||||
|
user_home, script_sha256
|
||||||
|
);
|
||||||
|
cache_script_bin_name
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ Show template:
|
|||||||
$ rundart -t|--template [--output script.dart]
|
$ rundart -t|--template [--output script.dart]
|
||||||
|
|
||||||
Show scriptions:
|
Show scriptions:
|
||||||
$ rundart -l|--list
|
$ rundart -l|--list [filter]
|
||||||
|
|
||||||
Install script:
|
Install script:
|
||||||
$ rundart -i|--install <script.dart>
|
$ rundart -i|--install <script.dart>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Show template:
|
|||||||
$ rungo -t|--template [--output script.go]
|
$ rungo -t|--template [--output script.go]
|
||||||
|
|
||||||
Show scriptions:
|
Show scriptions:
|
||||||
$ rungo -l|--list
|
$ rungo -l|--list [filter]
|
||||||
|
|
||||||
Install script:
|
Install script:
|
||||||
$ rungo -i|--install <script.go>
|
$ rungo -i|--install <script.go>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Show template:
|
|||||||
$ runrs -t|--template [--output script.rs]
|
$ runrs -t|--template [--output script.rs]
|
||||||
|
|
||||||
Show scriptions:
|
Show scriptions:
|
||||||
$ runrs -l|--list
|
$ runrs -l|--list [filter]
|
||||||
|
|
||||||
Install script:
|
Install script:
|
||||||
$ runrs -i|--install <script.rs>
|
$ runrs -i|--install <script.rs>
|
||||||
@@ -7,7 +7,7 @@ Show template:
|
|||||||
$ runts -t|--template [--output script.ts]
|
$ runts -t|--template [--output script.ts]
|
||||||
|
|
||||||
Show scriptions:
|
Show scriptions:
|
||||||
$ runts -l|--list
|
$ runts -l|--list [filter]
|
||||||
|
|
||||||
Install script:
|
Install script:
|
||||||
$ runts -i|--install <script.ts>
|
$ runts -i|--install <script.ts>
|
||||||
|
|||||||
Reference in New Issue
Block a user