feat: v0.2.6
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -710,7 +710,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "runrs"
|
name = "runrs"
|
||||||
version = "0.2.5"
|
version = "0.2.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rust_util",
|
"rust_util",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "runrs"
|
name = "runrs"
|
||||||
version = "0.2.5"
|
version = "0.2.6"
|
||||||
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,8 +9,11 @@ readme = "README.md"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = ["switch-rust-lang"]
|
||||||
|
switch-rust-lang = []
|
||||||
switch-go-lang = []
|
switch-go-lang = []
|
||||||
|
switch-js-lang = []
|
||||||
|
switch-dart-lang = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
reqwest = { version = "0.11.14", features = ["blocking"] }
|
reqwest = { version = "0.11.14", features = ["blocking"] }
|
||||||
|
|||||||
18
justfile
18
justfile
@@ -4,6 +4,20 @@ _:
|
|||||||
install:
|
install:
|
||||||
cargo install --path .
|
cargo install --path .
|
||||||
|
|
||||||
build-run-go:
|
build-run-rust:
|
||||||
cargo build --release --features switch-go-lang
|
cargo build --release
|
||||||
|
|
||||||
|
build-run-go:
|
||||||
|
cargo build --release --no-default-features --features switch-go-lang
|
||||||
|
|
||||||
|
build-run-js:
|
||||||
|
cargo build --release --no-default-features --features switch-js-lang
|
||||||
|
|
||||||
|
build-run-dart:
|
||||||
|
cargo build --release --no-default-features --features switch-dart-lang
|
||||||
|
|
||||||
|
build-all:
|
||||||
|
@just build-run-rust
|
||||||
|
@just build-run-go
|
||||||
|
@just build-run-js
|
||||||
|
@just build-run-dart
|
||||||
19
src/help_dart.rs
Normal file
19
src/help_dart.rs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
pub fn print_help() {
|
||||||
|
println!(r##"rundart v{} - A Tool for Run dart Scripts
|
||||||
|
|
||||||
|
Show help:
|
||||||
|
$ rundart -h|--help
|
||||||
|
|
||||||
|
Show template:
|
||||||
|
$ rundart -t|--template
|
||||||
|
|
||||||
|
Show scriptions:
|
||||||
|
$ rundart -l|--list
|
||||||
|
|
||||||
|
Install script:
|
||||||
|
$ rundart -i|--install <script.dart>
|
||||||
|
|
||||||
|
"##,
|
||||||
|
env!("CARGO_PKG_VERSION")
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -13,9 +13,6 @@ $ rungo -l|--list
|
|||||||
Install script:
|
Install script:
|
||||||
$ rungo -i|--install <script.go>
|
$ rungo -i|--install <script.go>
|
||||||
|
|
||||||
Run script:
|
|
||||||
$ rungo <script.rs> [arguments]
|
|
||||||
|
|
||||||
Powered by gorun, know more reference: https://github.com/erning/gorun
|
Powered by gorun, know more reference: https://github.com/erning/gorun
|
||||||
|
|
||||||
"##,
|
"##,
|
||||||
|
|||||||
19
src/help_js.rs
Normal file
19
src/help_js.rs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
pub fn print_help() {
|
||||||
|
println!(r##"runjs v{} - A Tool for Run JS Scripts
|
||||||
|
|
||||||
|
Show help:
|
||||||
|
$ runjs -h|--help
|
||||||
|
|
||||||
|
Show template:
|
||||||
|
$ runjs -t|--template
|
||||||
|
|
||||||
|
Show scriptions:
|
||||||
|
$ runjs -l|--list
|
||||||
|
|
||||||
|
Install script:
|
||||||
|
$ runjs -i|--install <script.js>
|
||||||
|
|
||||||
|
"##,
|
||||||
|
env!("CARGO_PKG_VERSION")
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -5,10 +5,14 @@ use std::path::PathBuf;
|
|||||||
use rust_util::util_os::get_user_home;
|
use rust_util::util_os::get_user_home;
|
||||||
use crate::util::{SCRIPT_DOT_EXT, SCRIPT_HYPHEN_EXT};
|
use crate::util::{SCRIPT_DOT_EXT, SCRIPT_HYPHEN_EXT};
|
||||||
|
|
||||||
#[cfg(not(feature = "switch-go-lang"))]
|
#[cfg(feature = "switch-rust-lang")]
|
||||||
const SCRIPT_PATTERN: &'static str = "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/$NAME/src/main.rs";
|
const SCRIPT_PATTERN: &str = "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/$NAME/src/main.rs";
|
||||||
#[cfg(feature = "switch-go-lang")]
|
#[cfg(feature = "switch-go-lang")]
|
||||||
const SCRIPT_PATTERN: &'static str = "https://git.hatter.ink/hatter/go-scripts/raw/branch/main/$NAME/main.go";
|
const SCRIPT_PATTERN: &str = "https://git.hatter.ink/hatter/go-scripts/raw/branch/main/$NAME/main.go";
|
||||||
|
#[cfg(feature = "switch-js-lang")]
|
||||||
|
const SCRIPT_PATTERN: &str = "https://git.hatter.ink/hatter/js-scripts/raw/branch/main/$NAME/main.js";
|
||||||
|
#[cfg(feature = "switch-dart-lang")]
|
||||||
|
const SCRIPT_PATTERN: &str = "https://git.hatter.ink/hatter/dart-scripts/raw/branch/main/$NAME/main.dart";
|
||||||
|
|
||||||
pub fn install_script(args: Vec<&String>) {
|
pub fn install_script(args: Vec<&String>) {
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
|
|||||||
10
src/list.rs
10
src/list.rs
@@ -5,10 +5,14 @@ use std::fs;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use crate::util::{SCRIPT_DOT_EXT, SCRIPT_HYPHEN_EXT};
|
use crate::util::{SCRIPT_DOT_EXT, SCRIPT_HYPHEN_EXT};
|
||||||
|
|
||||||
#[cfg(not(feature = "switch-go-lang"))]
|
#[cfg(feature = "switch-rust-lang")]
|
||||||
const FILE_META: &'static str = "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/script-meta.json";
|
const FILE_META: &str = "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/script-meta.json";
|
||||||
#[cfg(feature = "switch-go-lang")]
|
#[cfg(feature = "switch-go-lang")]
|
||||||
const FILE_META: &'static str = "https://git.hatter.ink/hatter/go-scripts/raw/branch/main/script-meta.json";
|
const FILE_META: &str = "https://git.hatter.ink/hatter/go-scripts/raw/branch/main/script-meta.json";
|
||||||
|
#[cfg(feature = "switch-js-lang")]
|
||||||
|
const FILE_META: &str = "https://git.hatter.ink/hatter/js-scripts/raw/branch/main/script-meta.json";
|
||||||
|
#[cfg(feature = "switch-dart-lang")]
|
||||||
|
const FILE_META: &str = "https://git.hatter.ink/hatter/dart-scripts/raw/branch/main/script-meta.json";
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct ScriptMeta {
|
struct ScriptMeta {
|
||||||
|
|||||||
46
src/main.rs
46
src/main.rs
@@ -5,33 +5,32 @@ use std::env;
|
|||||||
|
|
||||||
use rust_util::util_os::get_user_home;
|
use rust_util::util_os::get_user_home;
|
||||||
|
|
||||||
#[cfg(not(feature = "switch-go-lang"))]
|
|
||||||
use crate::help_rs::print_help;
|
|
||||||
#[cfg(feature = "switch-go-lang")]
|
|
||||||
use crate::help_go::print_help;
|
|
||||||
use crate::install::install_script;
|
use crate::install::install_script;
|
||||||
use crate::list::list_scripts;
|
use crate::list::list_scripts;
|
||||||
use crate::util::{
|
use crate::util::{
|
||||||
build_script_command, get_run_script_bin_name, read_file_and_digest, run_script_command,
|
build_script_command, get_run_script_bin_name, read_file_and_digest, run_script_command,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "switch-rust-lang")]
|
||||||
|
mod help_rs;
|
||||||
#[cfg(feature = "switch-go-lang")]
|
#[cfg(feature = "switch-go-lang")]
|
||||||
mod help_go;
|
mod help_go;
|
||||||
#[cfg(not(feature = "switch-go-lang"))]
|
#[cfg(feature = "switch-js-lang")]
|
||||||
mod help_rs;
|
mod help_js;
|
||||||
|
#[cfg(feature = "switch-dart-lang")]
|
||||||
|
mod help_dart;
|
||||||
mod install;
|
mod install;
|
||||||
mod list;
|
mod list;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
#[cfg(not(feature = "switch-go-lang"))]
|
#[cfg(feature = "switch-rust-lang")]
|
||||||
const SCRIPT_TEMPLATE: &'static str = include_str!("script.template.rs");
|
|
||||||
#[cfg(feature = "switch-go-lang")]
|
|
||||||
const SCRIPT_TEMPLATE: &'static str = include_str!("script.template.go");
|
|
||||||
|
|
||||||
#[cfg(not(feature = "switch-go-lang"))]
|
|
||||||
const CMD_NAME: &str = "runrs";
|
const CMD_NAME: &str = "runrs";
|
||||||
#[cfg(feature = "switch-go-lang")]
|
#[cfg(feature = "switch-go-lang")]
|
||||||
const CMD_NAME: &str = "rungo";
|
const CMD_NAME: &str = "rungo";
|
||||||
|
#[cfg(feature = "switch-js-lang")]
|
||||||
|
const CMD_NAME: &str = "runjs";
|
||||||
|
#[cfg(feature = "switch-dart-lang")]
|
||||||
|
const CMD_NAME: &str = "rundart";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = env::args().skip(1).collect::<Vec<_>>();
|
let args = env::args().skip(1).collect::<Vec<_>>();
|
||||||
@@ -48,11 +47,25 @@ fn main() {
|
|||||||
.get(0)
|
.get(0)
|
||||||
.unwrap_or_else(|| failure_and_exit!("Must assign a script file name"));
|
.unwrap_or_else(|| failure_and_exit!("Must assign a script file name"));
|
||||||
if first_argument == "--help" || first_argument == "-h" {
|
if first_argument == "--help" || first_argument == "-h" {
|
||||||
print_help();
|
#[cfg(feature = "switch-rust-lang")]
|
||||||
|
help_rs::print_help();
|
||||||
|
#[cfg(feature = "switch-go-lang")]
|
||||||
|
help_go::print_help();
|
||||||
|
#[cfg(feature = "switch-js-lang")]
|
||||||
|
help_js::print_help();
|
||||||
|
#[cfg(feature = "switch-dart-lang")]
|
||||||
|
help_dart::print_help();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if first_argument == "--template" || first_argument == "-t" {
|
if first_argument == "--template" || first_argument == "-t" {
|
||||||
println!("{}", SCRIPT_TEMPLATE);
|
#[cfg(feature = "switch-rust-lang")]
|
||||||
|
println!("{}", include_str!("script.template.rs"));
|
||||||
|
#[cfg(feature = "switch-go-lang")]
|
||||||
|
println!("{}", include_str!("script.template.go"));
|
||||||
|
#[cfg(feature = "switch-js-lang")]
|
||||||
|
println!("{}", include_str!("script.template.js"));
|
||||||
|
#[cfg(feature = "switch-dart-lang")]
|
||||||
|
println!("{}", include_str!("script.template.dart"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if first_argument == "--list" || first_argument == "-l" {
|
if first_argument == "--list" || first_argument == "-l" {
|
||||||
@@ -64,10 +77,9 @@ fn main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "switch-go-lang")]
|
#[cfg(any(feature = "switch-go-lang", feature = "switch-js-lang", feature = "switch-dart-lang"))]
|
||||||
if true {
|
if true {
|
||||||
// rungo, and run .go file is not supported
|
failure_and_exit!("Only rust supports run by runrs.");
|
||||||
failure_and_exit!("Go script should run by gorun, template for: rungo -t");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let script_file = first_argument;
|
let script_file = first_argument;
|
||||||
|
|||||||
5
src/script.template.dart
Normal file
5
src/script.template.dart
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env dart
|
||||||
|
|
||||||
|
main(List<String> args) {
|
||||||
|
print("Hello world.");
|
||||||
|
}
|
||||||
3
src/script.template.js
Normal file
3
src/script.template.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env -S deno run --allow-env
|
||||||
|
|
||||||
|
console.log("Hello world.");
|
||||||
12
src/util.rs
12
src/util.rs
@@ -5,15 +5,23 @@ use std::process::Command;
|
|||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use std::{env, fs, process};
|
use std::{env, fs, process};
|
||||||
|
|
||||||
#[cfg(not(feature = "switch-go-lang"))]
|
#[cfg(feature = "switch-rust-lang")]
|
||||||
pub const SCRIPT_HYPHEN_EXT: &str = "-rs";
|
pub const SCRIPT_HYPHEN_EXT: &str = "-rs";
|
||||||
#[cfg(feature = "switch-go-lang")]
|
#[cfg(feature = "switch-go-lang")]
|
||||||
pub const SCRIPT_HYPHEN_EXT: &str = "-go";
|
pub const SCRIPT_HYPHEN_EXT: &str = "-go";
|
||||||
|
#[cfg(feature = "switch-js-lang")]
|
||||||
|
pub const SCRIPT_HYPHEN_EXT: &str = "-js";
|
||||||
|
#[cfg(feature = "switch-dart-lang")]
|
||||||
|
pub const SCRIPT_HYPHEN_EXT: &str = "-dart";
|
||||||
|
|
||||||
#[cfg(not(feature = "switch-go-lang"))]
|
#[cfg(feature = "switch-rust-lang")]
|
||||||
pub const SCRIPT_DOT_EXT: &str = ".rs";
|
pub const SCRIPT_DOT_EXT: &str = ".rs";
|
||||||
#[cfg(feature = "switch-go-lang")]
|
#[cfg(feature = "switch-go-lang")]
|
||||||
pub const SCRIPT_DOT_EXT: &str = ".go";
|
pub const SCRIPT_DOT_EXT: &str = ".go";
|
||||||
|
#[cfg(feature = "switch-js-lang")]
|
||||||
|
pub const SCRIPT_DOT_EXT: &str = ".js";
|
||||||
|
#[cfg(feature = "switch-dart-lang")]
|
||||||
|
pub const SCRIPT_DOT_EXT: &str = ".dart";
|
||||||
|
|
||||||
|
|
||||||
pub fn build_script_command(rust_script: PathBuf, script_file: &str, script_sha256: &str, cache_script_bin_name: &str) -> Command {
|
pub fn build_script_command(rust_script: PathBuf, script_file: &str, script_sha256: &str, cache_script_bin_name: &str) -> Command {
|
||||||
|
|||||||
Reference in New Issue
Block a user