From 95f7cbbf805435aea163fafb17e8fea8387d61df Mon Sep 17 00:00:00 2001 From: James Westby Date: Fri, 12 Jul 2024 20:22:08 +0100 Subject: [PATCH] Format --- src/cmd/list.rs | 13 ++++++++++--- src/cmd/mod.rs | 1 - src/context.rs | 5 ++++- src/targets/artifact/exec.rs | 6 +++++- src/targets/command/container.rs | 8 +++++++- src/targets/command/exec.rs | 20 +++++++++++++++++--- tests/test_exec_command.rs | 4 +++- tests/test_list.rs | 5 +++-- 8 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/cmd/list.rs b/src/cmd/list.rs index 0ecffd4..6f2289e 100644 --- a/src/cmd/list.rs +++ b/src/cmd/list.rs @@ -11,13 +11,20 @@ use crate::context::Context; pub struct ListCommand {} impl Execute for ListCommand { - fn execute(&self, context: Context, _cleanup_manager: Arc>) -> Result<()> { + fn execute( + &self, + context: Context, + _cleanup_manager: Arc>, + ) -> Result<()> { let mut targets = context.targets.iter().collect::>(); targets.sort_by(|a, b| a.0.cmp(b.0)); for (name, target) in targets { - println!("{} - {}", name, target.target_info().description.clone().unwrap_or_default()); + println!( + "{} - {}", + name, + target.target_info().description.clone().unwrap_or_default() + ); } Ok(()) } } - diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 7a3c69d..6f6ebf5 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -54,7 +54,6 @@ pub enum Commands { /// List available targets List(ListCommand), - // TODO: status, logs } diff --git a/src/context.rs b/src/context.rs index 7b3b24a..3f565dc 100644 --- a/src/context.rs +++ b/src/context.rs @@ -778,7 +778,10 @@ mod tests { #[test] fn uses_globals() { - let mut config = Config { globals: Some(HashMap::new()), ..Default::default() }; + let mut config = Config { + globals: Some(HashMap::new()), + ..Default::default() + }; config .globals .as_mut() diff --git a/src/targets/artifact/exec.rs b/src/targets/artifact/exec.rs index 8753dc0..b6f4f72 100644 --- a/src/targets/artifact/exec.rs +++ b/src/targets/artifact/exec.rs @@ -62,7 +62,11 @@ impl Buildable for ExecArtifact { &self.target_info.name, outputs, )?; - let env = self.env.iter().map(|s| context.resolve_substitutions(s, &self.target_info.name, outputs)).collect::>>()?; + let env = self + .env + .iter() + .map(|s| context.resolve_substitutions(s, &self.target_info.name, outputs)) + .collect::>>()?; debug!( "Building exec artifact for target <{}> with command <{}>", self.target_info.name, cmd diff --git a/src/targets/command/container.rs b/src/targets/command/container.rs index b9c0a77..12b259f 100644 --- a/src/targets/command/container.rs +++ b/src/targets/command/container.rs @@ -155,7 +155,13 @@ impl Startable for ContainerCommand { for pre_command in command.pre_commands.iter() { run_command(pre_command.as_str())?; } - spawn_command_with_pidfile(command.command.as_str(), &[], &pid_path, &log_path, log_start)?; + spawn_command_with_pidfile( + command.command.as_str(), + &[], + &pid_path, + &log_path, + log_start, + )?; // TODO: post_stop_commands outputs.store_output(self.target_info.name.clone(), "name", command.name.as_str()); if let Some(network) = command.network { diff --git a/src/targets/command/exec.rs b/src/targets/command/exec.rs index 2963ae0..8ccdd2d 100644 --- a/src/targets/command/exec.rs +++ b/src/targets/command/exec.rs @@ -82,7 +82,11 @@ impl Runnable for ExecCommand { ) -> Result<()> { // TODO: default_args let command = self.resolve_command(context, outputs, args)?; - let env = self.env.iter().map(|s| context.resolve_substitutions(s, &self.target_info.name, outputs)).collect::>>()?; + let env = self + .env + .iter() + .map(|s| context.resolve_substitutions(s, &self.target_info.name, outputs)) + .collect::>>()?; debug!( "Running target <{}> with command <{}>", self.target_info.name, command @@ -107,11 +111,21 @@ impl Startable for ExecCommand { let log_path = config_dir.join("log"); // TODO: default_args let cmd = self.resolve_command(context, outputs, args)?; - let env = self.env.iter().map(|s| context.resolve_substitutions(s, &self.target_info.name, outputs)).collect::>>()?; + let env = self + .env + .iter() + .map(|s| context.resolve_substitutions(s, &self.target_info.name, outputs)) + .collect::>>()?; let log_start = || { info!("[{}] Starting {}", self.target_info.name, cmd); }; - spawn_command_with_pidfile(cmd.as_str(), env.as_slice(), &pid_path, &log_path, log_start) + spawn_command_with_pidfile( + cmd.as_str(), + env.as_slice(), + &pid_path, + &log_path, + log_start, + ) } fn stop( diff --git a/tests/test_exec_command.rs b/tests/test_exec_command.rs index a91292f..97aa73c 100644 --- a/tests/test_exec_command.rs +++ b/tests/test_exec_command.rs @@ -71,5 +71,7 @@ fn test_env() { let mut cmd = test_context.get_command(); cmd.arg("run").arg("env"); - cmd.assert().success().stdout(predicate::str::contains("HELLO=world").trim()); + cmd.assert() + .success() + .stdout(predicate::str::contains("HELLO=world").trim()); } diff --git a/tests/test_list.rs b/tests/test_list.rs index 8e57701..a1996f9 100644 --- a/tests/test_list.rs +++ b/tests/test_list.rs @@ -20,6 +20,7 @@ fn test_list() { let mut cmd = test_context.get_command(); cmd.arg("list"); - cmd.assert().success().stdout(predicate::eq("artifact.exec.copy - \ncommand.container.hello - Hello world\n")); + cmd.assert().success().stdout(predicate::eq( + "artifact.exec.copy - \ncommand.container.hello - Hello world\n", + )); } -