private static void ExecuteCommand(int id) { if (id < 0 || id > Containers.Count) { Write("Invalid id"); return; } var container = Containers[id]; DockerResponse result; if (container.State == "running") { switch (CurrentMode) { case ContainerAction.Kill: result = Finder.KillContainer(container.Id); break; case ContainerAction.Stop: result = Finder.StopContainer(container.Id); break; case ContainerAction.NetworkDown: { var network = container.NetworkSettings.Networks.FirstOrDefault(); if (network.Key != null && network.Key.Equals(Config.ExpectedNetwork, StringComparison.InvariantCultureIgnoreCase)) { result = Finder.DisconnectContainer(container.Id, network.Value.NetworkID); } else { result = Finder.ConnectContainer(container.Id, NetworkMemory.NetworkId, NetworkMemory.GetOriginalIpAddressFor(container.Id)); } break; } default: result = DockerResponse.Ok; break; } } else if (container.State == "stopped" || container.State == "exited") { result = Finder.StartContainer(container.Id); } else { Containers = GetContainers(); Write($"Unknown state: {container.State}"); return; } Containers = GetContainers(); if (result == DockerResponse.Ok) { ReDraw(); } else { Write($"Result: {result.ToString()}"); } }