chore: fix formatting and clippy lints
This commit is contained in:
1 parent
8952bd5399
commit
9d9e959744
35 files changed
+1091
-582
No files matched your search
+33
-17
@@ -22,16 +22,31 @@ impl McpTool for EnvironmentHandler {
|
||||
|
||||
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> crate::error::Result<String> {
|
||||
let req: EnvironmentTool = serde_json::from_value(args).map_err(|e| e.to_string())?;
|
||||
let ns = req.namespace.unwrap_or_else(|| crate::models::default_namespace());
|
||||
let ns = req
|
||||
.namespace
|
||||
.unwrap_or_else(crate::models::default_namespace);
|
||||
match req.action {
|
||||
EnvAction::UpdateFingerprint => {
|
||||
let tool_versions = req.tool_versions.unwrap_or_default();
|
||||
let detected_os = req.os.unwrap_or_else(|| std::env::consts::OS.to_string());
|
||||
let detected_shell = req.shell
|
||||
let detected_shell = req
|
||||
.shell
|
||||
.or_else(|| std::env::var("SHELL").ok())
|
||||
.or_else(|| std::env::var("STARSHIP_SHELL").ok())
|
||||
.or_else(|| if std::env::var("PSModulePath").is_ok() { Some("pwsh".to_string()) } else { None })
|
||||
.or_else(|| if std::env::var("COMSPEC").is_ok() { Some("cmd".to_string()) } else { None })
|
||||
.or_else(|| {
|
||||
if std::env::var("PSModulePath").is_ok() {
|
||||
Some("pwsh".to_string())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.or_else(|| {
|
||||
if std::env::var("COMSPEC").is_ok() {
|
||||
Some("cmd".to_string())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| "unknown".to_string());
|
||||
|
||||
state.env.env_fingerprints.modify(|fps| {
|
||||
@@ -102,10 +117,7 @@ impl McpTool for EnvironmentHandler {
|
||||
}
|
||||
EnvAction::GetDetails => {
|
||||
let data = state.env.environments.read_with(|envs| {
|
||||
let filtered: Vec<_> = envs
|
||||
.iter()
|
||||
.filter(|e| e.namespace == ns)
|
||||
.collect();
|
||||
let filtered: Vec<_> = envs.iter().filter(|e| e.namespace == ns).collect();
|
||||
Ok::<String, crate::error::AppError>(serde_json::to_string(&filtered)?)
|
||||
})?;
|
||||
Ok(data)
|
||||
@@ -114,7 +126,6 @@ impl McpTool for EnvironmentHandler {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -143,7 +154,10 @@ mod tests {
|
||||
assert_eq!(res, "Env fingerprint updated");
|
||||
|
||||
let res2 = handler
|
||||
.execute(json!({"action": "read_fingerprint", "namespace": "global"}), state.clone())
|
||||
.execute(
|
||||
json!({"action": "read_fingerprint", "namespace": "global"}),
|
||||
state.clone(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| crate::error::AppError::Internal(e.to_string()))
|
||||
.unwrap();
|
||||
@@ -171,7 +185,10 @@ mod tests {
|
||||
|
||||
let handler = EnvironmentHandler;
|
||||
let res = handler
|
||||
.execute(json!({"action": "get_details", "namespace": "global"}), state.clone())
|
||||
.execute(
|
||||
json!({"action": "get_details", "namespace": "global"}),
|
||||
state.clone(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| crate::error::AppError::Internal(e.to_string()))
|
||||
.unwrap();
|
||||
@@ -215,7 +232,10 @@ mod tests {
|
||||
assert_eq!(res2, "Environment registered");
|
||||
|
||||
let res3 = handler
|
||||
.execute(json!({"action": "get_details", "namespace": "global"}), state.clone())
|
||||
.execute(
|
||||
json!({"action": "get_details", "namespace": "global"}),
|
||||
state.clone(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| crate::error::AppError::Internal(e.to_string()))
|
||||
.unwrap();
|
||||
@@ -237,12 +257,8 @@ mod tests {
|
||||
}
|
||||
});
|
||||
|
||||
let res = handler
|
||||
.execute(args, state.clone())
|
||||
.await;
|
||||
let res = handler.execute(args, state.clone()).await;
|
||||
|
||||
assert!(res.is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user