feat: v0.2.5, support go scripts

This commit is contained in:
2024-12-29 17:13:41 +08:00
parent affcb233bd
commit 3ace53b509
11 changed files with 163 additions and 31 deletions

View File

@@ -3,8 +3,12 @@ use serde::Deserialize;
use std::collections::BTreeMap;
use std::fs;
use std::path::PathBuf;
use crate::util::{SCRIPT_DOT_EXT, SCRIPT_HYPHEN_EXT};
#[cfg(not(feature = "switch-go-lang"))]
const FILE_META: &'static str = "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/script-meta.json";
#[cfg(feature = "switch-go-lang")]
const FILE_META: &'static str = "https://git.hatter.ink/hatter/go-scripts/raw/branch/main/script-meta.json";
#[derive(Deserialize)]
struct ScriptMeta {
@@ -16,14 +20,14 @@ struct ScriptMeta {
pub fn list_scripts() {
debugging!("Loading URL: {}", FILE_META);
let response = reqwest::blocking::get(FILE_META).unwrap_or_else(|e| {
failure_and_exit!("Get file-meta.txt failed: {}", e);
failure_and_exit!("Get file-meta.json failed: {}", e);
});
debugging!("Load response: {}", response.status().as_u16());
if response.status().as_u16() != 200 {
failure_and_exit!("Get file-meta.txt failed, status: {}", response.status().as_u16());
failure_and_exit!("Get file-meta.json failed, status: {}", response.status().as_u16());
}
let text = response.text().unwrap_or_else(|e| {
failure_and_exit!("Get file-meta.txt failed: {}", e);
failure_and_exit!("Get file-meta.json failed: {}", e);
});
debugging!("Response text: {}", &text);
@@ -33,8 +37,8 @@ pub fn list_scripts() {
messages.push(format!("Found {} script(s):", script_meta_map.len()));
for (_, script_meta) in &script_meta_map {
let script_name = &script_meta.script_name;
let real_script_name = if script_name.ends_with("-rs") {
script_name.chars().take(script_name.len() - 3).collect::<String>() + ".rs"
let real_script_name = if script_name.ends_with(SCRIPT_HYPHEN_EXT) {
script_name.chars().take(script_name.len() - 3).collect::<String>() + SCRIPT_DOT_EXT
} else {
script_name.to_string()
};