diff --git a/cmd/soroban-cli/src/commands/network/container/logs.rs b/cmd/soroban-cli/src/commands/network/container/logs.rs index ceafb2a8b..6d2908edc 100644 --- a/cmd/soroban-cli/src/commands/network/container/logs.rs +++ b/cmd/soroban-cli/src/commands/network/container/logs.rs @@ -24,7 +24,7 @@ pub struct Cmd { impl Cmd { pub async fn run(&self) -> Result<(), Error> { - let container_name = Name::new(Some(self.name.clone()), None).get_internal_container_name(); + let container_name = Name::new(self.name.clone()).get_internal_container_name(); let docker = self.container_args.connect_to_docker().await?; let logs_stream = &mut docker.logs( &container_name, diff --git a/cmd/soroban-cli/src/commands/network/container/shared.rs b/cmd/soroban-cli/src/commands/network/container/shared.rs index 04ec9a807..5f4ac1166 100644 --- a/cmd/soroban-cli/src/commands/network/container/shared.rs +++ b/cmd/soroban-cli/src/commands/network/container/shared.rs @@ -126,26 +126,18 @@ impl fmt::Display for Network { } } -pub struct Name(Option, Option); +pub struct Name(String); impl Name { - pub fn new(name: Option, network: Option) -> Self { - Self(name, network) + pub fn new(name: String) -> Self { + Self(name) } pub fn get_internal_container_name(&self) -> String { - match (&self.0, &self.1) { - (Some(name), _) => format!("stellar-{}", name), - (None, Some(network)) => format!("stellar-{}", network), - (None, None) => panic!("Container name and/or network are required."), - } + format!("stellar-{}", self.0) } pub fn get_external_container_name(&self) -> String { - match (&self.0, &self.1) { - (Some(name), _) => name.to_string(), - (None, Some(network)) => network.to_string(), - (None, None) => panic!("Container name and/or network are required."), - } + self.0.to_string() } } @@ -186,62 +178,4 @@ async fn check_docker_connection(docker: &Docker) -> Result<(), bollard::errors: Err(err) } } -} - -#[cfg(test)] -mod tests { - use super::*; - - const NETWORK: Network = Network::Local; - const CONTAINER_NAME: &str = "test-name"; - - #[test] - fn test_get_internal_container_name_with_both_args() { - let name = Name::new(Some(CONTAINER_NAME.to_string()), Some(NETWORK)); - assert_eq!(name.get_internal_container_name(), "stellar-test-name"); - } - - #[test] - fn test_get_internal_container_name_with_network() { - let name = Name::new(None, Some(NETWORK)); - assert_eq!(name.get_internal_container_name(), "stellar-local"); - } - - #[test] - fn test_get_internal_container_name_with_name() { - // in practice, this would fail clap validation and we would never get here, but testing anyway - let name = Name::new(Some(CONTAINER_NAME.to_string()), None); - assert_eq!(name.get_internal_container_name(), "stellar-test-name"); - } - - #[test] - #[should_panic] - fn test_get_internal_container_name_with_neither_args() { - Name::new(None, None).get_internal_container_name(); - } - - #[test] - fn test_get_external_container_name_with_both_args() { - let name = Name::new(Some(CONTAINER_NAME.to_string()), Some(NETWORK)); - assert_eq!(name.get_external_container_name(), "test-name"); - } - - #[test] - fn test_get_external_container_name_with_network() { - let name = Name::new(None, Some(NETWORK)); - assert_eq!(name.get_external_container_name(), "local"); - } - - #[test] - fn test_get_external_container_name_with_name() { - // in practice, this would fail clap validation and we would never get here, but testing anyway - let name = Name::new(Some(CONTAINER_NAME.to_string()), None); - assert_eq!(name.get_external_container_name(), "test-name"); - } - - #[test] - #[should_panic] - fn test_get_external_container_name_with_neither_args() { - Name::new(None, None).get_external_container_name(); - } -} +} \ No newline at end of file diff --git a/cmd/soroban-cli/src/commands/network/container/start.rs b/cmd/soroban-cli/src/commands/network/container/start.rs index 7fb4f9450..35bf166c1 100644 --- a/cmd/soroban-cli/src/commands/network/container/start.rs +++ b/cmd/soroban-cli/src/commands/network/container/start.rs @@ -164,7 +164,7 @@ impl Cmd { } fn container_name(&self) -> Name { - Name::new(self.name.clone(), Some(self.network)) + Name::new(self.name.clone().unwrap_or(self.network.to_string())) } fn print_log_message(&self) { diff --git a/cmd/soroban-cli/src/commands/network/container/stop.rs b/cmd/soroban-cli/src/commands/network/container/stop.rs index 10be48ce4..c47dda32d 100644 --- a/cmd/soroban-cli/src/commands/network/container/stop.rs +++ b/cmd/soroban-cli/src/commands/network/container/stop.rs @@ -29,7 +29,7 @@ pub struct Cmd { impl Cmd { pub async fn run(&self) -> Result<(), Error> { - let container_name = Name::new(Some(self.name.clone()), None); + let container_name = Name::new(self.name.clone()); let docker = self.container_args.connect_to_docker().await?; println!( "ℹ️ Stopping container: {}",