qemu_command_builder/
tpmdev.rs1use std::path::PathBuf;
2
3use bon::Builder;
4
5use crate::to_command::ToCommand;
6
7#[derive(Default, Builder)]
8pub struct Passthrough {
9 id: String,
10 path: Option<PathBuf>,
11 cancel_path: Option<PathBuf>,
12}
13
14impl ToCommand for Passthrough {
15 fn to_command(&self) -> Vec<String> {
16 let mut cmd = vec![];
17
18 let mut args = vec![
19 "passthrough".to_string(),
20 format!("id={}", self.id.to_string()),
21 ];
22
23 if let Some(path) = &self.path {
24 args.push(format!("path={}", path.display()));
25 }
26 if let Some(cancel_path) = &self.cancel_path {
27 args.push(format!("cancel-path={}", cancel_path.display()));
28 }
29
30 cmd.push(args.join(","));
31 cmd
32 }
33}
34
35#[derive(Default, Builder)]
36pub struct Emulator {
37 id: String,
38 chardev: String,
39}
40
41impl ToCommand for Emulator {
42 fn to_command(&self) -> Vec<String> {
43 let mut cmd = vec![];
44
45 let args = [
46 "emulator".to_string(),
47 format!("id={}", self.id),
48 format!("chardev={}", self.chardev),
49 ];
50
51 cmd.push(args.join(","));
52 cmd
53 }
54}
55
56pub enum TpmDev {
57 Passthrough(Passthrough),
58 Emulator(Emulator),
59}
60
61impl ToCommand for TpmDev {
62 fn to_command(&self) -> Vec<String> {
63 let mut cmd = vec![];
64
65 cmd.push("-tpmdev".to_string());
66
67 match self {
68 TpmDev::Passthrough(p) => cmd.append(&mut p.to_command()),
69 TpmDev::Emulator(e) => cmd.append(&mut e.to_command()),
70 }
71
72 cmd
73 }
74}