feat: 0.2.7
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -710,7 +710,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "runrs"
|
||||
version = "0.2.6"
|
||||
version = "0.2.7"
|
||||
dependencies = [
|
||||
"reqwest",
|
||||
"rust_util",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "runrs"
|
||||
version = "0.2.6"
|
||||
version = "0.2.7"
|
||||
edition = "2018"
|
||||
license = "MIT/Apache-2.0"
|
||||
description = "A Tool for Run Rust Scripts"
|
||||
|
||||
20
src/list.rs
20
src/list.rs
@@ -21,7 +21,7 @@ struct ScriptMeta {
|
||||
script_sha256: String,
|
||||
}
|
||||
|
||||
pub fn list_scripts() {
|
||||
pub fn list_scripts(filter: Option<&String>) {
|
||||
debugging!("Loading URL: {}", FILE_META);
|
||||
let response = reqwest::blocking::get(FILE_META).unwrap_or_else(|e| {
|
||||
failure_and_exit!("Get file-meta.json failed: {}", e);
|
||||
@@ -35,10 +35,10 @@ pub fn list_scripts() {
|
||||
});
|
||||
debugging!("Response text: {}", &text);
|
||||
|
||||
let user_home = get_user_home().expect("Get user home failed!");
|
||||
let script_meta_map: BTreeMap<String, ScriptMeta> = serde_json::from_str(&text).expect("Parse script-meta.json failed.");
|
||||
|
||||
let mut messages = vec![];
|
||||
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(SCRIPT_HYPHEN_EXT) {
|
||||
@@ -46,7 +46,14 @@ pub fn list_scripts() {
|
||||
} else {
|
||||
script_name.to_string()
|
||||
};
|
||||
let user_home = get_user_home().expect("Get user home failed!");
|
||||
|
||||
if let Some(filter) = filter {
|
||||
if !real_script_name.contains(filter) {
|
||||
// NOT CONTAINS `filter`, SKIP
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
let full_script_path = PathBuf::from(&user_home).join("bin").join(&real_script_name);
|
||||
let is_script_exists = full_script_path.is_file();
|
||||
let script_sha256 = if is_script_exists {
|
||||
@@ -59,11 +66,16 @@ pub fn list_scripts() {
|
||||
let script_size = rust_util::util_size::get_display_size(script_meta.script_length as i64);
|
||||
let padding_length = 40 - real_script_name.len();
|
||||
messages.push(format!("- {} {} {} {}",
|
||||
iff!(is_script_exists, iff!(is_script_matches, "✅", "✔️ "), "❌"),
|
||||
iff!(is_script_exists, iff!(is_script_matches, "✅", "✔️ "), "➖"),
|
||||
real_script_name,
|
||||
".".repeat(iff!(padding_length < 1, 1, padding_length)),
|
||||
script_size,
|
||||
));
|
||||
}
|
||||
if filter.is_some() {
|
||||
messages.insert(0, format!("Total {} script(s), found {} script(s):", script_meta_map.len(), messages.len()));
|
||||
} else {
|
||||
messages.insert(0, format!("Found {} script(s):", script_meta_map.len()));
|
||||
}
|
||||
success!("{}", messages.join("\n"));
|
||||
}
|
||||
@@ -69,7 +69,8 @@ fn main() {
|
||||
return;
|
||||
}
|
||||
if first_argument == "--list" || first_argument == "-l" {
|
||||
list_scripts();
|
||||
let filter = args.get(1);
|
||||
list_scripts(filter);
|
||||
return;
|
||||
}
|
||||
if first_argument == "--install" || first_argument == "-i" {
|
||||
|
||||
Reference in New Issue
Block a user