Skip to main content

Mountain/IPC/WindServiceHandler/
Command.rs

1#![allow(non_snake_case)]
2
3//! Command registry domain handlers for Wind IPC.
4
5use std::sync::Arc;
6
7use serde_json::{Value, json};
8use CommonLibrary::Command::CommandExecutor::CommandExecutor;
9
10use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
11
12/// Execute a command by ID, dispatching to Mountain's CommandExecutor.
13pub async fn handle_commands_execute(Runtime:Arc<ApplicationRunTime>, Args:Vec<Value>) -> Result<Value, String> {
14	let CommandId = Args
15		.first()
16		.and_then(|V| V.as_str())
17		.ok_or_else(|| "commands:execute requires string command_id as first argument".to_string())?
18		.to_string();
19
20	let Argument = Args.get(1).cloned().unwrap_or(Value::Null);
21
22	dev_log!("ipc", "commands:execute id={}", CommandId);
23
24	Runtime
25		.Environment
26		.ExecuteCommand(CommandId, Argument)
27		.await
28		.map_err(|Error| format!("commands:execute failed: {}", Error))
29}
30
31/// Return all registered command IDs from Mountain's CommandRegistry.
32pub async fn handle_commands_get_all(Runtime:Arc<ApplicationRunTime>) -> Result<Value, String> {
33	let Commands = Runtime
34		.Environment
35		.GetAllCommands()
36		.await
37		.map_err(|Error| format!("commands:getAll failed: {}", Error))?;
38
39	Ok(json!(Commands))
40}