diff --git a/app/Commands/StartCommand.php b/app/Commands/StartCommand.php index 30b63869..386cef6f 100644 --- a/app/Commands/StartCommand.php +++ b/app/Commands/StartCommand.php @@ -7,20 +7,12 @@ use App\InitializesCommands; use App\Shell\Docker; use App\Shell\Environment; -use Illuminate\Support\Arr; use Illuminate\Support\Str; -use Laravel\Prompts\Prompt; use LaravelZero\Framework\Commands\Command; use PhpSchool\CliMenu\CliMenu; use function App\clear_terminal; -use function Laravel\Prompts\error; -use function Laravel\Prompts\intro; use function Laravel\Prompts\note; -use function Laravel\Prompts\alert; -use function Laravel\Prompts\outro; use function Laravel\Prompts\select; -use function Laravel\Prompts\spin; -use function Laravel\Prompts\warning; class StartCommand extends Command { @@ -170,7 +162,6 @@ private function defaultMenu($startableContainers) $options['Close'] = 'Close'; - return select( label: self::MENU_TITLE, options: $options, diff --git a/app/Commands/StopCommand.php b/app/Commands/StopCommand.php index 03a77d46..0586c04d 100644 --- a/app/Commands/StopCommand.php +++ b/app/Commands/StopCommand.php @@ -2,6 +2,8 @@ namespace App\Commands; +use App\Exceptions\DockerMissingException; +use App\Exceptions\DockerNotAvailableException; use App\InitializesCommands; use App\Shell\Docker; use App\Shell\Environment; @@ -9,6 +11,9 @@ use Illuminate\Support\Str; use LaravelZero\Framework\Commands\Command; use PhpSchool\CliMenu\CliMenu; +use function App\clear_terminal; +use function Laravel\Prompts\note; +use function Laravel\Prompts\select; class StopCommand extends Command { @@ -18,13 +23,21 @@ class StopCommand extends Command protected $signature = 'stop {containerId?*} {--all}'; protected $description = 'Stop one ore more started containers.'; - protected $docker; - protected $environment; - public function handle(Docker $docker, Environment $environment): void + public function __construct( + protected Docker $docker, + protected Environment $environment + ) + { + parent::__construct(); + } + + /** + * @throws DockerMissingException + * @throws DockerNotAvailableException + */ + public function handle(): void { - $this->docker = $docker; - $this->environment = $environment; $this->initializeCommand(); $containers = $this->argument('containerId'); @@ -45,13 +58,24 @@ public function handle(Docker $docker, Environment $environment): void return; } - if (! $stoppableContainers = $this->stoppableContainers()) { - $this->info("No Takeout containers available to stop.\n"); + if (!$stoppableContainers = $this->stoppableContainers()) { + note("No Takeout containers available to stop.\n"); return; } - $this->loadMenu($stoppableContainers); + do { + $item = $this->loadMenu($this->stoppableContainers()); + + if ($item === 'Close') { + break; + } + + $this->stop($item); + clear_terminal(5); + } while (true); + + clear_terminal(4); } public function stoppableContainers(): array @@ -99,7 +123,7 @@ public function stopByServiceNameOrContainerId(string $serviceNameOrContainerId) ]; })->all()); - if (! $selectedContainer) { + if (!$selectedContainer) { return; } @@ -126,15 +150,27 @@ private function loadMenu($stoppableContainers) private function defaultMenu($stoppableContainers) { - return $this->menu(self::MENU_TITLE) - ->addItems($stoppableContainers) - ->addLineBreak('', 1) - ->open(); + if (count($stoppableContainers) === 0) { + return 'Close'; + } + + $options = []; + foreach ($stoppableContainers as $stoppableContainer) { + $options[$stoppableContainer[0]] = $stoppableContainer[0]; + } + + $options['Close'] = 'Close'; + + return select( + label: self::MENU_TITLE, + options: $options, + scroll: 10 + ); } private function windowsMenu($stoppableContainers) { - if (! $stoppableContainers) { + if (!$stoppableContainers) { return; }