futucli/cli/dispatch/
daemon.rs1use anyhow::Result;
2
3use crate::cmd;
4use crate::output::OutputFormat;
5
6fn rest_url_or_port(rest_url: Option<String>, rest_port: Option<u16>) -> Option<String> {
7 rest_url.or_else(|| rest_port.map(|p| format!("http://127.0.0.1:{p}")))
10}
11
12pub(super) async fn dispatch_status(
13 rest_url: Option<String>,
14 rest_port: Option<u16>,
15 api_key: Option<String>,
16 output: OutputFormat,
17) -> Result<()> {
18 let effective_url = rest_url_or_port(rest_url, rest_port);
19 cmd::daemon::run_status(effective_url.as_deref(), api_key.as_deref(), output).await
20}
21
22pub(super) async fn dispatch_shutdown(
23 rest_url: Option<String>,
24 rest_port: Option<u16>,
25 api_key: Option<String>,
26) -> Result<()> {
27 let effective_url = rest_url_or_port(rest_url, rest_port);
28 cmd::daemon::run_shutdown(effective_url.as_deref(), api_key.as_deref()).await
29}
30
31pub(super) async fn dispatch_reload(
32 rest_url: Option<String>,
33 rest_port: Option<u16>,
34 api_key: Option<String>,
35) -> Result<()> {
36 let effective_url = rest_url_or_port(rest_url, rest_port);
37 cmd::daemon::run_reload(effective_url.as_deref(), api_key.as_deref()).await
38}