Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
james-w committed Jul 12, 2024
1 parent b2511bd commit 95f7cbb
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 13 deletions.
13 changes: 10 additions & 3 deletions src/cmd/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ use crate::context::Context;
pub struct ListCommand {}

impl Execute for ListCommand {
fn execute(&self, context: Context, _cleanup_manager: Arc<Mutex<CleanupManager>>) -> Result<()> {
fn execute(
&self,
context: Context,
_cleanup_manager: Arc<Mutex<CleanupManager>>,
) -> Result<()> {
let mut targets = context.targets.iter().collect::<Vec<_>>();
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(())
}
}

1 change: 0 additions & 1 deletion src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ pub enum Commands {

/// List available targets
List(ListCommand),

// TODO: status, logs
}

Expand Down
5 changes: 4 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion src/targets/artifact/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Result<Vec<String>>>()?;
let env = self
.env
.iter()
.map(|s| context.resolve_substitutions(s, &self.target_info.name, outputs))
.collect::<Result<Vec<String>>>()?;
debug!(
"Building exec artifact for target <{}> with command <{}>",
self.target_info.name, cmd
Expand Down
8 changes: 7 additions & 1 deletion src/targets/command/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 17 additions & 3 deletions src/targets/command/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Result<Vec<String>>>()?;
let env = self
.env
.iter()
.map(|s| context.resolve_substitutions(s, &self.target_info.name, outputs))
.collect::<Result<Vec<String>>>()?;
debug!(
"Running target <{}> with command <{}>",
self.target_info.name, command
Expand All @@ -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::<Result<Vec<String>>>()?;
let env = self
.env
.iter()
.map(|s| context.resolve_substitutions(s, &self.target_info.name, outputs))
.collect::<Result<Vec<String>>>()?;
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(
Expand Down
4 changes: 3 additions & 1 deletion tests/test_exec_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
5 changes: 3 additions & 2 deletions tests/test_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
));
}

0 comments on commit 95f7cbb

Please sign in to comment.