Skip to main content

Mountain/RPC/CocoonService/Command/
RegisterCommand.rs

1#![allow(non_snake_case)]
2
3//! Wire a Cocoon-contributed command into Mountain's `CommandExecutor` as
4//! a Proxied handler that forwards back to the sidecar.
5
6use CommonLibrary::Command::CommandExecutor::CommandExecutor;
7use tonic::{Response, Status};
8
9use crate::{
10	RPC::CocoonService::CocoonServiceImpl,
11	Vine::Generated::{Empty, RegisterCommandRequest},
12	dev_log,
13};
14
15pub async fn Fn(Service:&CocoonServiceImpl, Request:RegisterCommandRequest) -> Result<Response<Empty>, Status> {
16	dev_log!(
17		"cocoon",
18		"[CocoonService] Registering command '{}' from extension '{}'",
19		Request.command_id,
20		Request.extension_id
21	);
22
23	if let Err(Error) = Service
24		.environment
25		.RegisterCommand(Request.extension_id.clone(), Request.command_id.clone())
26		.await
27	{
28		dev_log!(
29			"cocoon",
30			"warn: [CocoonService] Failed to register command '{}': {:?}",
31			Request.command_id,
32			Error
33		);
34	} else {
35		dev_log!(
36			"cocoon",
37			"[CocoonService] Command registered: id={}, title={:?}",
38			Request.command_id,
39			Request.title
40		);
41	}
42
43	Ok(Response::new(Empty {}))
44}