From 5c77d8db769d86ab8dc64b54c2f529b685898c13 Mon Sep 17 00:00:00 2001
From: daimond113 <72147841+daimond113@users.noreply.github.com>
Date: Sun, 17 Mar 2024 01:19:53 +0100
Subject: [PATCH] refactor(cli): :art: use static variables
---
Cargo.lock | 57 +++---
Cargo.toml | 3 +-
registry/src/endpoints/packages.rs | 5 +-
src/cli/api_token.rs | 147 +++++++++++++++
src/cli/auth.rs | 25 ++-
src/cli/config.rs | 20 +-
src/cli/mod.rs | 274 +++++++++++++++++++++++++++
src/cli/root.rs | 75 ++++----
src/dependencies/git.rs | 2 +-
src/dependencies/mod.rs | 4 +-
src/main.rs | 288 +----------------------------
src/multithread.rs | 7 +-
12 files changed, 520 insertions(+), 387 deletions(-)
create mode 100644 src/cli/api_token.rs
diff --git a/Cargo.lock b/Cargo.lock
index 3fdf260..5509e06 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -92,7 +92,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb"
dependencies = [
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -130,7 +130,7 @@ dependencies = [
"parse-size",
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -243,7 +243,7 @@ dependencies = [
"actix-router",
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -571,7 +571,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -600,13 +600,13 @@ checksum = "fbb36e985947064623dbd357f727af08ffd077f93d696782f3c56365fa2e2799"
[[package]]
name = "async-trait"
-version = "0.1.77"
+version = "0.1.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9"
+checksum = "461abc97219de0eaaf81fe3ef974a540158f3d079c2ab200f891f1a2ef201e85"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -925,7 +925,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -1146,7 +1146,7 @@ dependencies = [
"proc-macro2",
"quote",
"strsim 0.10.0",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -1157,7 +1157,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f"
dependencies = [
"darling_core",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -1363,7 +1363,7 @@ checksum = "5c785274071b1b420972453b306eeca06acf4633829db4223b58a2a8c5953bc4"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -1711,7 +1711,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -2604,9 +2604,9 @@ dependencies = [
[[package]]
name = "luau0-src"
-version = "0.8.4+luau616"
+version = "0.8.5+luau617"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "74f34c6c8e52606273c5d689b722e03383e58fed85840868885301fe9038fbd9"
+checksum = "652e36b8c35d807ec76a4931fe7c62883c62cc93311fb49bf5b76084647078ea"
dependencies = [
"cc",
]
@@ -3103,7 +3103,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -3263,6 +3263,7 @@ dependencies = [
"keyring",
"log",
"lune",
+ "once_cell",
"pathdiff",
"pretty_env_logger",
"relative-path",
@@ -3280,7 +3281,7 @@ dependencies = [
[[package]]
name = "pesde-registry"
-version = "0.4.0"
+version = "0.5.0"
dependencies = [
"actix-cors",
"actix-governor",
@@ -3325,7 +3326,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -3470,7 +3471,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8021cf59c8ec9c432cfc2526ac6b8aa508ecaf29cd415f271b8406c1b851c3fd"
dependencies = [
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -4320,7 +4321,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -4352,7 +4353,7 @@ checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -4653,9 +4654,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "2.0.52"
+version = "2.0.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07"
+checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032"
dependencies = [
"proc-macro2",
"quote",
@@ -4888,7 +4889,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -5022,7 +5023,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -5180,7 +5181,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
@@ -5474,7 +5475,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
"wasm-bindgen-shared",
]
@@ -5508,7 +5509,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@@ -5872,7 +5873,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.52",
+ "syn 2.0.53",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 6a72a95..7de702c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,7 +9,7 @@ homepage = "https://pesde.daimond113.com"
include = ["src/**/*", "Cargo.toml", "Cargo.lock", "README.md", "LICENSE", "CHANGELOG.md"]
[features]
-bin = ["clap", "directories", "keyring", "anyhow", "ignore", "pretty_env_logger", "serde_json", "reqwest/json", "reqwest/multipart", "lune", "futures-executor", "indicatif", "auth-git2", "indicatif-log-bridge", "inquire"]
+bin = ["clap", "directories", "keyring", "anyhow", "ignore", "pretty_env_logger", "serde_json", "reqwest/json", "reqwest/multipart", "lune", "futures-executor", "indicatif", "auth-git2", "indicatif-log-bridge", "inquire", "once_cell"]
[[bin]]
name = "pesde"
@@ -48,6 +48,7 @@ indicatif = { version = "0.17.8", optional = true }
auth-git2 = { version = "0.5.4", optional = true }
indicatif-log-bridge = { version = "0.2.2", optional = true }
inquire = { version = "0.7.1", optional = true }
+once_cell = { version = "1.19.0", optional = true }
[dev-dependencies]
tempfile = "3.10.1"
diff --git a/registry/src/endpoints/packages.rs b/registry/src/endpoints/packages.rs
index 0d8311c..e4d301f 100644
--- a/registry/src/endpoints/packages.rs
+++ b/registry/src/endpoints/packages.rs
@@ -174,10 +174,7 @@ pub async fn get_package_version(
match index.package(&package_name)? {
Some(package) => {
if version == "latest" {
- version = package
- .last()
- .map(|v| v.version.to_string())
- .unwrap();
+ version = package.last().map(|v| v.version.to_string()).unwrap();
} else if !package.iter().any(|v| v.version.to_string() == version) {
return Ok(HttpResponse::NotFound().finish());
}
diff --git a/src/cli/api_token.rs b/src/cli/api_token.rs
new file mode 100644
index 0000000..f5ec99d
--- /dev/null
+++ b/src/cli/api_token.rs
@@ -0,0 +1,147 @@
+use std::path::PathBuf;
+
+use keyring::Entry;
+use once_cell::sync::Lazy;
+use serde::{Deserialize, Serialize};
+
+use crate::cli::INDEX_DIR;
+
+pub trait ApiTokenSource: Send + Sync {
+ fn get_api_token(&self) -> anyhow::Result