audb_core/features/
shell.rs1use crate::features::config::{device_store::DeviceStore, state::DeviceState};
6use crate::tools::{
7 session::DeviceSession,
8 types::DeviceIdentifier,
9};
10use anyhow::{anyhow, Context, Result};
11
12pub async fn execute(as_root: bool, command: String) -> Result<()> {
13 if command.is_empty() {
14 return Err(anyhow!("Command required. Usage: audb shell <command>"));
15 }
16
17 let current_host = DeviceState::get_current()?;
19 let device_id = DeviceIdentifier::Host(current_host);
20 let device = DeviceStore::find(&device_id)?;
21
22 let mut session = DeviceSession::connect(&device)
23 .context("Failed to connect to device")?;
24
25 let output = if as_root {
27 session.exec_as_root(&command)
28 .context("Failed to execute command as root. Set root password using: audb device add")?
29 } else {
30 session.exec(&command)
31 .context("Failed to execute command")?
32 };
33
34 for line in output {
36 println!("{}", line);
37 }
38
39 Ok(())
40}