From e283a210adb9f1c4988354178498b656e7a32ee1 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Thu, 23 Feb 2023 01:05:53 +0800 Subject: [PATCH] feat: v0.2.2 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/list.rs | 28 ++++++++++++++++++++++++++++ src/main.rs | 6 ++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/list.rs diff --git a/Cargo.lock b/Cargo.lock index d25fd16..7445d97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -626,7 +626,7 @@ dependencies = [ [[package]] name = "runrs" -version = "0.2.1" +version = "0.2.2" dependencies = [ "reqwest", "rust_util", diff --git a/Cargo.toml b/Cargo.toml index 1c0fb5a..ea860a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/list.rs b/src/list.rs new file mode 100644 index 0000000..42a34fe --- /dev/null +++ b/src/list.rs @@ -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::() + ".rs" + } else { + script.to_string() + }; + format!("- {}", script) + }).collect::>().join("\n") + ); +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 88d8324..28cc148 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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;