diff --git a/app/Commands/HelpCommand.php b/app/Commands/HelpCommand.php index dc720f0..e165e8f 100644 --- a/app/Commands/HelpCommand.php +++ b/app/Commands/HelpCommand.php @@ -18,7 +18,7 @@ class HelpCommand extends Command 'start {container}' => 'Start the provided stopped containers (by ID)', 'stop' => 'Stop a running container from a list of options (optionally pass --all flag)', 'stop {container}' => 'Stop the provided running containers (by ID)', - 'list' => 'List all enabled services (optionally pass --json flag)', + 'list' => 'List all enabled services (optionally pass --json or --networking flag)', 'logs {container}' => 'Display container logs (by ID)', ]; diff --git a/app/Commands/ListCommand.php b/app/Commands/ListCommand.php index 183a757..ef7c59f 100644 --- a/app/Commands/ListCommand.php +++ b/app/Commands/ListCommand.php @@ -11,14 +11,14 @@ class ListCommand extends Command { use InitializesCommands; - protected $signature = 'list {--json}'; + protected $signature = 'list {--json} {--networking}'; protected $description = 'List all services enabled by Takeout.'; public function handle(Docker $docker): void { $this->initializeCommand(); - $containersCollection = $docker->takeoutContainers(); + $containersCollection = $docker->takeoutContainers(boolval($this->option('networking'))); if ($this->option('json')) { $this->line($containersCollection->map(function ($item) { diff --git a/app/Shell/Docker.php b/app/Shell/Docker.php index d183ad3..5654a2d 100644 --- a/app/Shell/Docker.php +++ b/app/Shell/Docker.php @@ -98,15 +98,12 @@ public function allContainers(): Collection ); } - public function takeoutContainers(): Collection + public function takeoutContainers(bool $withNetworking = false): Collection { - $process = sprintf( - 'docker ps -a --filter "name=TO-" --format "table %s|%s"', - '{{.ID}}|{{.Names}}|{{.Status}}|{{.Ports}}', - '{{.Label \"com.tighten.takeout.Base_Alias\"}}|{{.Label \"com.tighten.takeout.Full_Alias\"}}' - ); - - return $this->runAndParseTable($process); + return $this->runAndParseTable(sprintf( + 'docker ps -a --filter \'name=TO-\' --format \'table {{.ID}}|{{.Names}}|{{.Status}}|{{.Ports}}%s\'', + $withNetworking ? '|{{.Label "com.tighten.takeout.Base_Alias"}}|{{.Label "com.tighten.takeout.Full_Alias"}}' : '', + )); } public function startableTakeoutContainers(): Collection