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

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")
);
}