1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
use std::marker::PhantomData;
use derivative::Derivative;
use serde::{Deserialize, Serialize};
use crate::ShCmd;
/// Grouping of commands to run a shell command idempotently.
///
/// The `Id` type parameter is needed for each command execution params to be a
/// distinct type.
///
/// # Type Parameters
///
/// * `Id`: A zero-sized type used to distinguish different command execution
/// parameters from each other.
#[derive(Derivative, PartialEq, Eq, Deserialize, Serialize)]
#[derivative(Clone, Debug)]
pub struct ShCmdParams<Id> {
/// Shell command to run to discover the clean state.
///
/// The command's stdout is used as the clean state.
///
/// The command's stderr is used as the human readable description of the
/// state. This must be output as a single line.
state_clean_sh_cmd: ShCmd,
/// Shell command to run to discover the current state.
///
/// The command's stdout is used as the current state.
///
/// The command's stderr is used as the human readable description of the
/// state. This must be output as a single line.
state_current_sh_cmd: ShCmd,
/// Shell command to run to discover the desired state.
///
/// The command's stdout is used as the desired state.
///
/// The command's stderr is used as the human readable description of the
/// state. This must be output as a single line.
state_desired_sh_cmd: ShCmd,
/// Shell command to run to show the state difference.
///
/// The command will be passed the following as two separate arguments:
///
/// * Current state string
/// * Desired state string
///
/// The command's stdout is used as the state difference.
///
/// The command's stderr is used as the human readable description of the
/// state difference. This must be output as a single line.
state_diff_sh_cmd: ShCmd,
/// Shell command to run in `ApplyFns::check`.
///
/// The command will be passed the following as three separate arguments:
///
/// * Current state string
/// * Desired state string
/// * State diff string
///
/// If the shell command returns the string `true` as its final line, then
/// it is taken to mean `ApplyFns::exec` needs to be run.
///
/// If the shell command returns the string `false` as its final line, then
/// it is taken to mean `ApplyFns::exec` does not need to be run.
apply_check_sh_cmd: ShCmd,
/// Shell command to run in `ApplyFns::exec`.
///
/// The command will be passed the following as three separate arguments:
///
/// * Current state string
/// * Desired state string
/// * State diff string
apply_exec_sh_cmd: ShCmd,
/// Marker for unique command execution parameters type.
marker: PhantomData<Id>,
}
impl<Id> ShCmdParams<Id> {
/// Returns new `ShCmdParams`.
#[allow(clippy::too_many_arguments)]
pub fn new(
state_clean_sh_cmd: ShCmd,
state_current_sh_cmd: ShCmd,
state_desired_sh_cmd: ShCmd,
state_diff_sh_cmd: ShCmd,
apply_check_sh_cmd: ShCmd,
apply_exec_sh_cmd: ShCmd,
) -> Self {
Self {
state_clean_sh_cmd,
state_current_sh_cmd,
state_desired_sh_cmd,
state_diff_sh_cmd,
apply_check_sh_cmd,
apply_exec_sh_cmd,
marker: PhantomData,
}
}
/// Returns the shell command to run to discover the clean state.
///
/// The command's stdout is used as the clean state.
///
/// The command's stderr is used as the human readable description of the
/// state. This must be output as a single line.
pub fn state_clean_sh_cmd(&self) -> &ShCmd {
&self.state_clean_sh_cmd
}
/// Returns the shell command to run to discover the current state.
///
/// The command's stdout is used as the current state.
///
/// The command's stderr is used as the human readable description of the
/// state. This must be output as a single line.
pub fn state_current_sh_cmd(&self) -> &ShCmd {
&self.state_current_sh_cmd
}
/// Returns the shell command to run to discover the desired state.
///
/// The command's stdout is used as the desired state.
///
/// The command's stderr is used as the human readable description of the
/// state. This must be output as a single line.
pub fn state_desired_sh_cmd(&self) -> &ShCmd {
&self.state_desired_sh_cmd
}
/// Returns the shell command to run to show the state difference.
///
/// The command will be passed the following as three separate arguments:
///
/// * Current state string
/// * Desired state string
///
/// The command's stdout is used as the state difference.
///
/// The command's stderr is used as the human readable description of the
/// state difference. This must be output as a single line.
pub fn state_diff_sh_cmd(&self) -> &ShCmd {
&self.state_diff_sh_cmd
}
/// Returns the shell command to run in `ApplyFns::check`.
///
/// The command will be passed the following as three separate arguments:
///
/// * Current state string
/// * Desired state string
/// * State diff string
///
/// If the shell command returns the string `true` as its final line, then
/// it is taken to mean `ApplyFns::exec` needs to be run.
///
/// If the shell command returns the string `false` as its final line, then
/// it is taken to mean `ApplyFns::exec` does not need to be run.
pub fn apply_check_sh_cmd(&self) -> &ShCmd {
&self.apply_check_sh_cmd
}
/// Returns the shell command to run in `ApplyFns::exec`.
///
/// The command will be passed the following as three separate arguments:
///
/// * Current state string
/// * Desired state string
/// * State diff string
pub fn apply_exec_sh_cmd(&self) -> &ShCmd {
&self.apply_exec_sh_cmd
}
}