Skip to content

Commit

Permalink
Clippy & cleanup errors
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Jul 3, 2024
1 parent b7610d4 commit 6e3b601
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
25 changes: 14 additions & 11 deletions cmd/soroban-cli/src/commands/network/container/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const DOCKER_IMAGE: &str = "docker.io/stellar/quickstart";
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("⛔ ️Failed to connect to docker: {0}")]
ConnectionError(#[from] ConnectionError),
DockerConnectionFailed(#[from] ConnectionError),

#[error("⛔ ️Failed to create container: {0}")]
BollardErr(#[from] bollard::errors::Error),
CreateContainerFailed(#[from] bollard::errors::Error),
}

#[derive(Debug, clap::Parser, Clone)]
Expand All @@ -37,7 +37,7 @@ pub struct Cmd {
#[arg(short = 'l', long)]
pub limits: Option<String>,

/// Argument to specify the HOST_PORT:CONTAINER_PORT mapping
/// Argument to specify the `HOST_PORT:CONTAINER_PORT` mapping
#[arg(short = 'p', long, num_args = 1.., default_value = DEFAULT_PORT_MAPPING)]
pub ports_mapping: Vec<String>,

Expand Down Expand Up @@ -118,11 +118,11 @@ fn print_log_message(cmd: &Cmd) {
"ℹ️ 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)
|container_name| format!("--container-name {container_name}")
),
additional_flags = cmd.container_args.docker_host.as_ref().map_or_else(
|| String::new(),
|docker_host| format!("--docker-host {}", docker_host)
String::new,
|docker_host| format!("--docker-host {docker_host}")
)
);
println!("{log_message}");
Expand All @@ -133,12 +133,15 @@ fn print_stop_message(cmd: &Cmd) {
"ℹ️ 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)
|container_name| format!("--container-name {container_name}")
),
additional_flags = cmd.container_args.docker_host.as_ref().map_or_else(
|| String::new(),
|docker_host| format!("--docker-host {}", docker_host)
)
additional_flags = cmd
.container_args
.docker_host
.as_ref()
.map_or_else(String::new, |docker_host| format!(
"--docker-host {docker_host}"
))
);
println!("{stop_message}");
}
Expand Down
18 changes: 9 additions & 9 deletions cmd/soroban-cli/src/commands/network/container/stop.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use crate::commands::network::container::shared::{
connect_to_docker, get_container_name, Error as ConnectionError, Network,
connect_to_docker, get_container_name, Error as BollardConnectionError, Network,
};

use super::shared::ContainerArgs;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Failed to stop container: {0}")]
StopConnectionContainerError(#[from] ConnectionError),
#[error("Failed to connect to docker: {0}")]
DockerConnectionFailed(#[from] BollardConnectionError),

#[error("Container {container_name} not found")]
ContainerNotFoundError {
#[error("Container {container_name} not found")]
ContainerNotFound {
container_name: String,
#[source]
source: bollard::errors::Error,
},

#[error("Failed to stop container: {0}")]
StopContainerError(#[from] bollard::errors::Error),
#[error("Failed to stop container: {0}")]
ContainerStopFailed(#[from] bollard::errors::Error),
}

#[derive(Debug, clap::Parser, Clone)]
Expand All @@ -42,12 +42,12 @@ impl Cmd {
.map_err(|e| {
let msg = e.to_string();
if msg.contains("No such container") {
Error::ContainerNotFoundError {
Error::ContainerNotFound {
container_name: container_name.clone(),
source: e,
}
} else {
Error::StopContainerError(e)
Error::ContainerStopFailed(e)
}
})?;
println!("✅ Container stopped: {container_name}");
Expand Down

0 comments on commit 6e3b601

Please sign in to comment.