1use containers_api::{
2 impl_field, impl_opts_builder, impl_str_enum_field, impl_str_field, impl_vec_field,
3};
4use std::fmt;
5
6impl_opts_builder!(json =>
7 ExecCreate
9);
10
11#[derive(Debug, Clone)]
12pub enum UserOpt {
14 User(String),
15 UserGroup(String, String),
16 Uid(isize),
17 UidGid(isize, isize),
18}
19
20impl fmt::Display for UserOpt {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 use UserOpt::*;
23 match self {
24 User(user) => write!(f, "{user}"),
25 Uid(uid) => write!(f, "{uid}"),
26 UserGroup(user, group) => write!(f, "{user}:{group}"),
27 UidGid(uid, gid) => write!(f, "{uid}:{gid}"),
28 }
29 }
30}
31
32impl ExecCreateOptsBuilder {
33 impl_field!(
34 attach_stderr: bool => "AttachStderr"
36 );
37
38 impl_field!(
39 attach_stdin: bool => "AttachStdin"
41 );
42
43 impl_field!(
44 attach_stdout: bool => "AttachStdout"
46 );
47
48 impl_vec_field!(
49 command => "Cmd"
51 );
52
53 impl_str_field!(
54 detach_keys => "DetachKeys"
56 );
57
58 pub fn env<K, V>(mut self, vars: impl IntoIterator<Item = (K, V)>) -> Self
60 where
61 K: AsRef<str>,
62 V: AsRef<str>,
63 {
64 self.params.insert(
65 "Env",
66 vars.into_iter()
67 .map(|(k, v)| format!("{}={}", k.as_ref(), v.as_ref()))
68 .collect(),
69 );
70 self
71 }
72
73 impl_field!(
74 privileged: bool => "Privileged"
76 );
77
78 impl_field!(
79 tty: bool => "Tty"
81 );
82
83 impl_str_enum_field!(
84 user: UserOpt => "User"
86 );
87
88 impl_str_field!(
89 working_dir => "WorkingDir"
91 );
92}
93
94impl_opts_builder!(json =>
95 ExecStart
97);
98
99impl ExecStartOptsBuilder {
100 impl_field!(
101 detach: bool => "Detach"
103 );
104
105 impl_field!(
106 height: usize => "h"
108 );
109
110 impl_field!(
111 tty: bool => "Tty"
113 );
114
115 impl_field!(
116 width: usize => "w"
118 );
119}