qemu_command_builder/
runwith.rs1use crate::common::OnOff;
2use crate::to_command::{ToArg, ToCommand};
3use bon::Builder;
4use std::path::PathBuf;
5
6#[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
7pub enum UserOrIds {
8 User(String),
9 Id { uid: usize, gid: usize },
10}
11#[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq, Default, Builder)]
12pub struct RunWith {
13 async_teardown: Option<OnOff>,
14 chroot: Option<PathBuf>,
15 user: Option<UserOrIds>,
16}
17
18impl ToCommand for RunWith {
19 fn to_command(&self) -> Vec<String> {
20 let mut cmd = vec![];
21
22 cmd.push("-run-with".to_string());
23
24 let mut args = vec![];
25
26 if let Some(async_teardown) = &self.async_teardown {
27 args.push(format!("async-teardown={}", async_teardown.to_arg()))
28 }
29 if let Some(chroot) = &self.chroot {
30 args.push(format!("chroot={}", chroot.display()));
31 }
32 if let Some(user) = &self.user {
33 match user {
34 UserOrIds::User(id) => {
35 args.push(format!("user={}", id));
36 }
37 UserOrIds::Id { uid, gid } => {
38 args.push(format!("user={}:{}", uid, gid));
39 }
40 }
41 }
42 cmd.push(args.join(","));
43 cmd
44 }
45}