feat: v0.2.2
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -626,7 +626,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "runrs"
|
name = "runrs"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rust_util",
|
"rust_util",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "runrs"
|
name = "runrs"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
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"
|
||||||
|
|||||||
28
src/list.rs
Normal file
28
src/list.rs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
const FILE_META: &'static str = "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/file-meta.txt";
|
||||||
|
|
||||||
|
pub fn list_scripts() {
|
||||||
|
let response = reqwest::blocking::get(FILE_META).unwrap_or_else(|e| {
|
||||||
|
failure_and_exit!("Get file-meta.txt failed: {}", e);
|
||||||
|
});
|
||||||
|
if response.status().as_u16() != 200 {
|
||||||
|
failure_and_exit!("Get file-meta.txt failed, status: {}", response.status().as_u16());
|
||||||
|
}
|
||||||
|
let text = response.text().unwrap_or_else(|e| {
|
||||||
|
failure_and_exit!("Get file-meta.txt failed: {}", e);
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut scripts: Vec<&str> = text.trim().split("\n").collect();
|
||||||
|
scripts.sort();
|
||||||
|
|
||||||
|
success!("Found {} script(s):\n{}",
|
||||||
|
scripts.len(),
|
||||||
|
scripts.iter().map(|script| {
|
||||||
|
let script = if script.ends_with("-rs") {
|
||||||
|
script.chars().take(script.len() - 3).collect::<String>() + ".rs"
|
||||||
|
} else {
|
||||||
|
script.to_string()
|
||||||
|
};
|
||||||
|
format!("- {}", script)
|
||||||
|
}).collect::<Vec<_>>().join("\n")
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -7,10 +7,12 @@ use rust_util::util_os::get_user_home;
|
|||||||
|
|
||||||
use crate::help::print_help;
|
use crate::help::print_help;
|
||||||
use crate::install::install_script;
|
use crate::install::install_script;
|
||||||
|
use crate::list::list_scripts;
|
||||||
use crate::util::{build_script_command, get_run_script_bin_name, read_file_and_digest, run_script_command};
|
use crate::util::{build_script_command, get_run_script_bin_name, read_file_and_digest, run_script_command};
|
||||||
|
|
||||||
mod util;
|
mod util;
|
||||||
mod help;
|
mod help;
|
||||||
|
mod list;
|
||||||
mod install;
|
mod install;
|
||||||
|
|
||||||
const SCRIPT_TEMPLATE: &'static str = include_str!("script.template");
|
const SCRIPT_TEMPLATE: &'static str = include_str!("script.template");
|
||||||
@@ -32,6 +34,10 @@ fn main() {
|
|||||||
println!("{}", SCRIPT_TEMPLATE);
|
println!("{}", SCRIPT_TEMPLATE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if first_argument == "--list" || first_argument == "-l" {
|
||||||
|
list_scripts();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if first_argument == "--install" || first_argument == "-i" {
|
if first_argument == "--install" || first_argument == "-i" {
|
||||||
install_script(args.iter().skip(1).collect());
|
install_script(args.iter().skip(1).collect());
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user