Skip to content

Commit

Permalink
Add get_container_name_arg fn on Args to reduce duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Jul 15, 2024
1 parent c81f788 commit ce13f84
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 7 additions & 0 deletions cmd/soroban-cli/src/commands/network/container/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ impl Args {
.map(|docker_host| format!("--docker-host {docker_host}"))
.unwrap_or_default()
}

pub(crate) fn get_container_name_arg(&self, network: Network) -> String {
self.container_name.as_ref().map_or_else(
|| network.to_string(),
|container_name| format!("--container-name {container_name}"),
)
}
}

#[derive(ValueEnum, Debug, Copy, Clone, PartialEq)]
Expand Down
10 changes: 2 additions & 8 deletions cmd/soroban-cli/src/commands/network/container/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ async fn run_docker_command(cmd: &Cmd) -> Result<(), Error> {
fn print_log_message(cmd: &Cmd) {
let log_message = format!(
"ℹ️ To see the logs for this container run: stellar network container logs {arg} {additional_flags}",
arg = cmd.container_args.container_name.as_ref().map_or_else(
|| cmd.network.to_string(),
|container_name| format!("--container-name {container_name}")
),
arg = cmd.container_args.get_container_name_arg(cmd.network),
additional_flags = cmd.container_args.get_additional_flags(),
);
println!("{log_message}");
Expand All @@ -128,10 +125,7 @@ fn print_log_message(cmd: &Cmd) {
fn print_stop_message(cmd: &Cmd) {
let stop_message = format!(
"ℹ️ To stop this container run: stellar network container stop {arg} {additional_flags}",
arg = cmd.container_args.container_name.as_ref().map_or_else(
|| cmd.network.to_string(),
|container_name| format!("--container-name {container_name}")
),
arg = cmd.container_args.get_container_name_arg(cmd.network),
additional_flags = cmd.container_args.get_additional_flags(),
);
println!("{stop_message}");
Expand Down

0 comments on commit ce13f84

Please sign in to comment.