Skip to content

Commit 7d941fd

Browse files
committed
Made ignore_fails, show_success_output and show_bash_c optional
1 parent 9d2db27 commit 7d941fd

File tree

9 files changed

+72
-206
lines changed

9 files changed

+72
-206
lines changed

deploy-config.yaml

Lines changed: 0 additions & 158 deletions
Large diffs are not rendered by default.

src/actions/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl Execute for TestAction {
6363
let mut output = vec![];
6464

6565
let (status, command_out) = self.command.execute(env)?;
66-
if !status && !self.command.ignore_fails {
66+
if !status && !self.command.ignore_fails.is_some_and(|v| v) {
6767
return Ok((false, command_out));
6868
}
6969

src/configs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ impl Default for DeployerGlobalConfig {
167167
bash_c: "cargo build --release".into(),
168168
placeholders: None,
169169
replacements: None,
170-
ignore_fails: false,
171-
show_success_output: false,
172-
show_bash_c: true,
170+
ignore_fails: None,
171+
show_success_output: None,
172+
show_bash_c: None,
173173
only_when_fresh: None,
174174
remote_exec: None,
175175
daemon: None,

src/configs/migrate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ fn migrate_custom_v3_to_v4(prev_cmd: &CustomCommandV3) -> CustomCommand {
2929
CustomCommand {
3030
bash_c: prev_cmd.bash_c.clone(),
3131
placeholders: prev_cmd.placeholders.clone(),
32-
ignore_fails: prev_cmd.ignore_fails,
33-
show_success_output: prev_cmd.show_success_output,
34-
show_bash_c: prev_cmd.show_bash_c,
32+
ignore_fails: if prev_cmd.ignore_fails { Some(true) } else { None },
33+
show_success_output: if prev_cmd.show_success_output { Some(true) } else { None },
34+
show_bash_c: if !prev_cmd.show_bash_c { Some(false) } else { None },
3535
only_when_fresh: prev_cmd.only_when_fresh,
3636
remote_exec: prev_cmd.remote_exec.clone(),
3737
daemon: None,

src/containered.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ pub fn run_simple(env: &RunEnvironment, bash_c: String) -> anyhow::Result<()> {
5454
log(format!("Given command: `{}`", bash_c));
5555
bash_c
5656
},
57-
ignore_fails: false,
57+
ignore_fails: None,
5858
only_when_fresh: None,
5959
placeholders: None,
6060
remote_exec: None,
6161
replacements: None,
62-
show_bash_c: true,
63-
show_success_output: true,
62+
show_bash_c: None,
63+
show_success_output: Some(true),
6464
daemon: None,
6565
daemon_wait_seconds: None,
6666
})

src/entities/custom_command.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,28 @@ pub struct CustomCommand {
3131
///
3232
/// Any status code your command returns which isn't equal zero means fail. But this
3333
/// flag allows to avoid Pipeline early exit, if needed. Error will be ignored.
34-
pub ignore_fails: bool,
34+
///
35+
/// Default is `false`.
36+
#[serde(skip_serializing_if = "Option::is_none")]
37+
pub ignore_fails: Option<bool>,
3538

3639
/// Flag to show output if the command was finished successfully.
3740
///
3841
/// E.g., if you don't wanna see `cargo build` output when code is built successfully,
3942
/// you can set this flag to `true`.
40-
pub show_success_output: bool,
43+
///
44+
/// Default is `false`.
45+
#[serde(skip_serializing_if = "Option::is_none")]
46+
pub show_success_output: Option<bool>,
4147

4248
/// Flag to show command on screen (during Pipeline execution).
4349
///
4450
/// Allows to hide constructed command (from `bash_c` and replaced variables) to avoid
4551
/// leaking secrets (keys, tokens, paths to sensitive files, etc.).
46-
pub show_bash_c: bool,
52+
///
53+
/// Default is `true`.
54+
#[serde(skip_serializing_if = "Option::is_none")]
55+
pub show_bash_c: Option<bool>,
4756

4857
/// Flag to run this command only once on repeateable builds.
4958
///
@@ -193,14 +202,14 @@ impl Execute for CustomCommand {
193202
stdout_strs,
194203
stderr_strs,
195204
command_output.status.success(),
196-
self.show_success_output,
197-
self.show_bash_c,
205+
self.show_success_output.is_some_and(|v| v),
206+
self.show_bash_c.is_none_or(|v| v),
198207
));
199208

200209
command_output.status.success()
201210
};
202211

203-
if !self.ignore_fails && !success {
212+
if !self.ignore_fails.is_some_and(|v| v) && !success {
204213
return Ok((false, output));
205214
}
206215
}
@@ -277,7 +286,7 @@ impl Execute for CustomCommand {
277286
res.success()
278287
};
279288

280-
if !self.ignore_fails && !success {
289+
if !self.ignore_fails.is_some_and(|v| v) && !success {
281290
return Ok((false, output));
282291
}
283292
}
@@ -328,7 +337,7 @@ impl CustomCommand {
328337
let remote = match globals.remote_hosts.get(hostname) {
329338
None => {
330339
output.push(i18n::NO_SUCH_REMOTE.to_string());
331-
if !self.ignore_fails {
340+
if !self.ignore_fails.is_some_and(|v| v) {
332341
return Ok((false, output));
333342
}
334343
continue;
@@ -346,13 +355,13 @@ impl CustomCommand {
346355
out,
347356
String::new(),
348357
s,
349-
self.show_success_output,
350-
self.show_bash_c,
358+
self.show_success_output.is_some_and(|v| v),
359+
self.show_bash_c.is_none_or(|v| v),
351360
);
352361
composed.pop();
353362
output.extend_from_slice(&composed);
354363

355-
if !self.ignore_fails && !s {
364+
if !self.ignore_fails.is_some_and(|v| v) && !s {
356365
RemoteHost::close_session(&mut session, &rt)?;
357366
return Ok((false, output));
358367
}

src/tui/add.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ impl TestAction {
301301
bash_c,
302302
placeholders,
303303
replacements: None,
304-
ignore_fails,
305-
show_success_output: true,
306-
show_bash_c: false,
304+
ignore_fails: if ignore_fails { Some(true) } else { None },
305+
show_success_output: Some(true),
306+
show_bash_c: Some(false),
307307
only_when_fresh: None,
308308
remote_exec: None,
309309
daemon: None,
@@ -343,9 +343,9 @@ impl TestAction {
343343
bash_c,
344344
placeholders: None,
345345
replacements: None,
346-
ignore_fails,
347-
show_success_output: true,
348-
show_bash_c: false,
346+
ignore_fails: if ignore_fails { Some(true) } else { None },
347+
show_success_output: Some(true),
348+
show_bash_c: Some(false),
349349
only_when_fresh: None,
350350
remote_exec: None,
351351
daemon: None,
@@ -840,7 +840,7 @@ impl AutoVersionExtractFromRule {
840840
i18n::AUTO_VER_CMD_STDOUT => AutoVersionExtractFromRule::CmdStdout {
841841
cmd: {
842842
let mut cmd = CustomCommand::new_from_prompt_unspecified()?;
843-
cmd.show_success_output = true;
843+
cmd.show_success_output = Some(true);
844844
cmd
845845
},
846846
},
@@ -870,12 +870,12 @@ impl CustomCommand {
870870
let ignore_fails = inquire::Confirm::new(i18n::CMD_IGNORE_FAILS)
871871
.with_default(false)
872872
.prompt()?;
873-
let show_bash_c = inquire::Confirm::new(i18n::CMD_SHOW_BASH_C)
874-
.with_default(true)
875-
.prompt()?;
876873
let show_success_output = inquire::Confirm::new(i18n::CMD_SHOW_SUCC_OUT)
877874
.with_default(false)
878875
.prompt()?;
876+
let show_bash_c = inquire::Confirm::new(i18n::CMD_SHOW_BASH_C)
877+
.with_default(true)
878+
.prompt()?;
879879
let only_when_fresh = Some(
880880
inquire::Confirm::new(i18n::CMD_ONLY_WHEN_FRESH)
881881
.with_default(false)
@@ -888,9 +888,9 @@ impl CustomCommand {
888888
Ok(CustomCommand {
889889
bash_c,
890890
placeholders,
891-
ignore_fails,
892-
show_bash_c,
893-
show_success_output,
891+
ignore_fails: if ignore_fails { Some(true) } else { None },
892+
show_success_output: if show_success_output { Some(true) } else { None },
893+
show_bash_c: if !show_bash_c { Some(false) } else { None },
894894
only_when_fresh,
895895
replacements: None,
896896
remote_exec,
@@ -912,9 +912,9 @@ impl CustomCommand {
912912
Ok(CustomCommand {
913913
bash_c,
914914
placeholders,
915-
ignore_fails: true,
916-
show_success_output: true,
917-
show_bash_c: false,
915+
ignore_fails: Some(true),
916+
show_success_output: Some(true),
917+
show_bash_c: Some(false),
918918
only_when_fresh: Some(false),
919919
replacements: None,
920920
remote_exec: None,

src/tui/edit.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,19 +1217,34 @@ impl Edit for CustomCommand {
12171217
};
12181218
}
12191219
i18n::CMD_CHANGE_FAILURE_IGNORANCE => {
1220-
self.ignore_fails = inquire::Confirm::new(i18n::CMD_IGNORE_FAILS)
1220+
self.ignore_fails = if inquire::Confirm::new(i18n::CMD_IGNORE_FAILS)
12211221
.with_default(false)
1222-
.prompt()?;
1223-
}
1224-
i18n::CMD_CHANGE_VISIBILITY_AT_BUILD => {
1225-
self.show_bash_c = inquire::Confirm::new(i18n::CMD_SHOW_BASH_C)
1226-
.with_default(true)
1227-
.prompt()?;
1222+
.prompt()?
1223+
{
1224+
Some(true)
1225+
} else {
1226+
None
1227+
};
12281228
}
12291229
i18n::CMD_CHANGE_VISIBILITY_ON_SUCC => {
1230-
self.show_success_output = inquire::Confirm::new(i18n::CMD_SHOW_SUCC_OUT)
1230+
self.show_success_output = if inquire::Confirm::new(i18n::CMD_SHOW_SUCC_OUT)
12311231
.with_default(false)
1232-
.prompt()?;
1232+
.prompt()?
1233+
{
1234+
Some(true)
1235+
} else {
1236+
None
1237+
};
1238+
}
1239+
i18n::CMD_CHANGE_VISIBILITY_AT_BUILD => {
1240+
self.show_bash_c = if !inquire::Confirm::new(i18n::CMD_SHOW_BASH_C)
1241+
.with_default(true)
1242+
.prompt()?
1243+
{
1244+
Some(false)
1245+
} else {
1246+
None
1247+
};
12331248
}
12341249
i18n::CMD_CHANGE_ON_FRESH => {
12351250
self.only_when_fresh = if inquire::Confirm::new(i18n::CMD_ONLY_WHEN_FRESH)
@@ -1499,7 +1514,7 @@ impl Edit for AddToStorageAction {
14991514
i18n::AUTO_VER_CMD_STDOUT => AutoVersionExtractFromRule::CmdStdout {
15001515
cmd: {
15011516
let mut cmd = CustomCommand::new_from_prompt_unspecified()?;
1502-
cmd.show_success_output = true;
1517+
cmd.show_success_output = Some(true);
15031518
cmd
15041519
},
15051520
},

src/tui/setup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl CustomCommand {
262262
let mut r = self.clone();
263263
r.replacements = Some(replacements);
264264
r.show_bash_c = if let Some(show) = explicitly_show_bash_c {
265-
show
265+
if !show { Some(false) } else { None }
266266
} else {
267267
r.show_bash_c
268268
};

0 commit comments

Comments
 (0)