Add post-commands (fix #505) (#515)

This commit is contained in:
Roey Darwish Dror
2020-08-30 07:40:06 +03:00
committed by GitHub
parent 6b37839b01
commit 10f3d929e8
2 changed files with 16 additions and 1 deletions

View File

@@ -164,6 +164,7 @@ pub struct Composer {
/// Configuration file /// Configuration file
pub struct ConfigFile { pub struct ConfigFile {
pre_commands: Option<Commands>, pre_commands: Option<Commands>,
post_commands: Option<Commands>,
commands: Option<Commands>, commands: Option<Commands>,
git_repos: Option<Vec<String>>, git_repos: Option<Vec<String>>,
predefined_git_repos: Option<bool>, predefined_git_repos: Option<bool>,
@@ -416,6 +417,11 @@ impl Config {
&self.config_file.pre_commands &self.config_file.pre_commands
} }
/// The list of commands to run at the end of all steps
pub fn post_commands(&self) -> &Option<Commands> {
&self.config_file.post_commands
}
/// The list of custom steps. /// The list of custom steps.
pub fn commands(&self) -> &Option<Commands> { pub fn commands(&self) -> &Option<Commands> {
&self.config_file.commands &self.config_file.commands

View File

@@ -350,6 +350,15 @@ fn run() -> Result<()> {
dragonfly::audit_packages(&sudo).ok(); dragonfly::audit_packages(&sudo).ok();
} }
let mut post_command_failed = false;
if let Some(commands) = config.post_commands() {
for (name, command) in commands {
if generic::run_custom_command(&name, &command, &ctx).is_err() {
post_command_failed = true;
}
}
}
if config.keep_at_end() { if config.keep_at_end() {
print_info("\n(R)eboot\n(S)hell\n(Q)uit"); print_info("\n(R)eboot\n(S)hell\n(Q)uit");
loop { loop {
@@ -369,7 +378,7 @@ fn run() -> Result<()> {
} }
} }
if runner.report().data().iter().any(|(_, result)| result.failed()) { if post_command_failed || runner.report().data().iter().any(|(_, result)| result.failed()) {
Err(StepFailed.into()) Err(StepFailed.into())
} else { } else {
Ok(()) Ok(())