Skip to main content

Mountain/RPC/CocoonService/GenericRequest/Commands/
ExecuteCommand.rs

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