Skip to content

Commit

Permalink
using prompts on stop command
Browse files Browse the repository at this point in the history
  • Loading branch information
r2luna committed Oct 20, 2023
1 parent f42c4e1 commit bbc388f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 23 deletions.
9 changes: 0 additions & 9 deletions app/Commands/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -170,7 +162,6 @@ private function defaultMenu($startableContainers)

$options['Close'] = 'Close';


return select(
label: self::MENU_TITLE,
options: $options,
Expand Down
64 changes: 50 additions & 14 deletions app/Commands/StopCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

namespace App\Commands;

use App\Exceptions\DockerMissingException;
use App\Exceptions\DockerNotAvailableException;
use App\InitializesCommands;
use App\Shell\Docker;
use App\Shell\Environment;
use Illuminate\Support\Arr;
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
{
Expand All @@ -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
)
{

Check failure on line 31 in app/Commands/StopCommand.php

View workflow job for this annotation

GitHub Actions / PHPCS

The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
parent::__construct();
}

/**
* @throws DockerMissingException
* @throws DockerNotAvailableException
*/
public function handle(): void
{
$this->docker = $docker;
$this->environment = $environment;
$this->initializeCommand();

$containers = $this->argument('containerId');
Expand All @@ -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()) {

Check failure on line 61 in app/Commands/StopCommand.php

View workflow job for this annotation

GitHub Actions / PHPCS

Expected 1 space(s) after NOT operator; 0 found
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
Expand Down Expand Up @@ -99,7 +123,7 @@ public function stopByServiceNameOrContainerId(string $serviceNameOrContainerId)
];
})->all());

if (! $selectedContainer) {
if (!$selectedContainer) {

Check failure on line 126 in app/Commands/StopCommand.php

View workflow job for this annotation

GitHub Actions / PHPCS

Expected 1 space(s) after NOT operator; 0 found
return;
}

Expand All @@ -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) {

Check failure on line 173 in app/Commands/StopCommand.php

View workflow job for this annotation

GitHub Actions / PHPCS

Expected 1 space(s) after NOT operator; 0 found
return;
}

Expand Down

0 comments on commit bbc388f

Please sign in to comment.