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_push_sub_info(
23 args: crate::cli::commands::PushSubscriberInfoArgs,
24 output: OutputFormat,
25) -> Result<()> {
26 let crate::cli::commands::PushSubscriberInfoArgs {
27 rest_url,
28 rest_port,
29 api_key,
30 } = args;
31 let effective_url = rest_url_or_port(rest_url, rest_port);
32 cmd::daemon::run_push_subscriber_info(effective_url.as_deref(), api_key.as_deref(), output)
33 .await
34}
35
36pub(super) async fn dispatch_doctor(
37 args: crate::cli::commands::DoctorArgs,
38 output: OutputFormat,
39) -> Result<()> {
40 let crate::cli::commands::DoctorArgs {
41 rest_url,
42 rest_port,
43 api_key,
44 symbol,
45 bundle,
46 no_update_check,
47 update_url,
48 update_timeout_ms,
49 } = args;
50 let effective_url = rest_url_or_port(rest_url, rest_port);
51 cmd::daemon::run_doctor(
52 effective_url.as_deref(),
53 api_key.as_deref(),
54 symbol.as_deref(),
55 bundle.as_deref(),
56 !no_update_check,
57 update_url.as_deref(),
58 update_timeout_ms,
59 output,
60 )
61 .await
62}
63
64pub(super) async fn dispatch_shutdown(
65 rest_url: Option<String>,
66 rest_port: Option<u16>,
67 api_key: Option<String>,
68) -> Result<()> {
69 let effective_url = rest_url_or_port(rest_url, rest_port);
70 cmd::daemon::run_shutdown(effective_url.as_deref(), api_key.as_deref()).await
71}
72
73pub(super) async fn dispatch_reload(
74 rest_url: Option<String>,
75 rest_port: Option<u16>,
76 api_key: Option<String>,
77) -> Result<()> {
78 let effective_url = rest_url_or_port(rest_url, rest_port);
79 cmd::daemon::run_reload(effective_url.as_deref(), api_key.as_deref()).await
80}