feat: v0.2.2

This commit is contained in:
2023-02-23 01:05:53 +08:00
parent 2d620e963e
commit e283a210ad
4 changed files with 36 additions and 2 deletions

2
Cargo.lock generated
View File

@@ -626,7 +626,7 @@ dependencies = [
[[package]]
name = "runrs"
version = "0.2.1"
version = "0.2.2"
dependencies = [
"reqwest",
"rust_util",

View File

@@ -1,6 +1,6 @@
[package]
name = "runrs"
version = "0.2.1"
version = "0.2.2"
edition = "2018"
license = "MIT/Apache-2.0"
description = "A Tool for Run Rust Scripts"

28
src/list.rs Normal file
View 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")
);
}

View File

@@ -7,10 +7,12 @@ use rust_util::util_os::get_user_home;
use crate::help::print_help;
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};
mod util;
mod help;
mod list;
mod install;
const SCRIPT_TEMPLATE: &'static str = include_str!("script.template");
@@ -32,6 +34,10 @@ fn main() {
println!("{}", SCRIPT_TEMPLATE);
return;
}
if first_argument == "--list" || first_argument == "-l" {
list_scripts();
return;
}
if first_argument == "--install" || first_argument == "-i" {
install_script(args.iter().skip(1).collect());
return;