Skip to content

Commit

Permalink
fix: newlines between commands run in a configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianbenavides committed Jan 6, 2025
1 parent 15c8e51 commit 7225929
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
33 changes: 27 additions & 6 deletions implementations/rust/ockam/ockam_command/src/node/create/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ impl NodeConfig {
self.kafka_outlet.into_parsed_commands(node_name)?.into(),
self.kafka_inlet.into_parsed_commands(node_name)?.into(),
];
for section in other_sections {
section.run(ctx, opts).await?;
}
opts.terminal.write_line("")?;
Self::run_commands_sections(ctx, opts, other_sections).await?;
opts.terminal.write_line("")?;

// Block on the node until it exits
let _ = node_handle.await.into_diagnostic()?;
Expand All @@ -297,9 +297,8 @@ impl NodeConfig {
node_name: &String,
identity_name: &String,
) -> miette::Result<()> {
for section in self.parse_commands(node_name, identity_name)? {
section.run(ctx, opts).await?
}
let sections = self.parse_commands(node_name, identity_name)?;
Self::run_commands_sections(ctx, opts, sections).await?;
Ok(())
}

Expand Down Expand Up @@ -328,6 +327,28 @@ impl NodeConfig {
self.kafka_inlet.into_parsed_commands(node_name)?.into(),
])
}

async fn run_commands_sections(
ctx: &Context,
opts: &CommandGlobalOpts,
sections: Vec<ParsedCommands>,
) -> miette::Result<()> {
let sections: Vec<ParsedCommands> = sections
.into_iter()
.filter(|s| !s.commands.is_empty())
.collect();
let len = sections.len();
for (idx, section) in sections.into_iter().enumerate() {
if section.commands.is_empty() {
continue;
}
section.run(ctx, opts).await?;
if idx < len - 1 {
opts.terminal.write_line("")?;
}
}
Ok(())
}
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ impl ParsedCommands {
/// Validate and run each command
pub async fn run(self, ctx: &Context, opts: &CommandGlobalOpts) -> Result<()> {
let len = self.commands.len();
if len > 0 {
opts.terminal.write_line("")?;
}
for cmd in self.commands.into_iter() {
for (idx, cmd) in self.commands.into_iter().enumerate() {
if cmd.is_valid(ctx, opts).await? {
cmd.run(ctx, opts).await?;
// Newline after each command
opts.terminal.write_line("")?;
if idx < len - 1 {
opts.terminal.write_line("")?;
}
}
}
Ok(())
Expand Down

0 comments on commit 7225929

Please sign in to comment.