Mountain/RPC/CocoonService/GenericRequest/Commands/
ExecuteCommand.rs1use serde_json::{Value, json};
2use tonic::Response;
3use CommonLibrary::Command::CommandExecutor::CommandExecutor;
4use ::Vine::Generated::GenericResponse;
5
6use crate::Environment::MountainEnvironment::MountainEnvironment;
7
8pub async fn Fn(RequestId:u64, Params:Value, Env:&MountainEnvironment) -> Response<GenericResponse> {
9 let CommandId = Params.get("commandId").and_then(|V| V.as_str()).unwrap_or("").to_string();
10
11 let Arg = Params
12 .get("arguments")
13 .and_then(|A| A.as_array())
14 .and_then(|A| A.first())
15 .cloned()
16 .unwrap_or(Value::Null);
17
18 match Env.ExecuteCommand(CommandId, Arg).await {
19 Ok(V) => super::super::FileSystem::OkResponse(RequestId, &json!({ "result": V })),
20
21 Err(Error) => super::super::FileSystem::ErrResponse(RequestId, -32000, Error.to_string()),
22 }
23}