1pub mod args;
6mod collaborative_reboot;
7pub mod connector;
8mod debugcmd;
9mod system_activity;
10
11use anyhow::{Context, Result};
12use args::{PowerCommand, PowerSubCommand};
13use connector::Connector;
14use std::io::Write;
15
16pub async fn power(
17 cmd: PowerCommand,
18 connector: impl Connector,
19 writer: &mut dyn Write,
20) -> Result<()> {
21 match cmd.subcommand {
22 PowerSubCommand::SystemActivity(subcmd) => {
23 let system_activity_control = connector
24 .get_system_activity_control()
25 .await
26 .context("Failed to get system_activity_control")?;
27 system_activity::system_activity(subcmd, writer, system_activity_control)
28 .await
29 .context("system-activity subcommand failed")?;
30 }
31 PowerSubCommand::Debugcmd(subcmd) => {
32 let debug_proxy =
33 connector.get_debug().await.context("Failed to get power manager debug proxy")?;
34 debugcmd::debugcmd(subcmd, debug_proxy).await.context("debugcmd subcommand failed")?;
35 }
36 PowerSubCommand::CollaborativeReboot(subcmd) => {
37 let reboot_initiator = connector
38 .get_reboot_initiator()
39 .await
40 .context("Failed to get system_activity_control")?;
41 collaborative_reboot::collaborative_reboot(writer, subcmd, reboot_initiator)
42 .await
43 .context("collaborative-reboot subcommand failed")?;
44 }
45 };
46 Ok(())
47}