Skip to content

Commit 8c0b9f5

Browse files
committed
Fix styling
1 parent 9387cb2 commit 8c0b9f5

File tree

7 files changed

+91
-99
lines changed

7 files changed

+91
-99
lines changed

packages/prompts/src/Filament/Components/RunCommandComponent.php

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,39 @@
22

33
namespace Moox\Prompts\Filament\Components;
44

5-
use Filament\Forms\Components\TextInput;
6-
use Filament\Forms\Components\Textarea;
7-
use Filament\Forms\Components\Select;
85
use Filament\Forms\Components\Checkbox;
96
use Filament\Forms\Components\Placeholder;
107
use Filament\Forms\Components\Radio;
8+
use Filament\Forms\Components\Select;
9+
use Filament\Forms\Components\Textarea;
10+
use Filament\Forms\Components\TextInput;
1111
use Filament\Forms\Concerns\InteractsWithForms;
1212
use Filament\Forms\Contracts\HasForms;
13+
use Illuminate\Console\OutputStyle;
1314
use Livewire\Component;
1415
use Moox\Prompts\Support\PendingPromptsException;
1516
use Moox\Prompts\Support\PromptResponseStore;
1617
use Symfony\Component\Console\Input\ArrayInput;
1718
use Symfony\Component\Console\Output\BufferedOutput;
18-
use Illuminate\Console\OutputStyle;
1919

2020
class RunCommandComponent extends Component implements HasForms
2121
{
2222
use InteractsWithForms;
2323

2424
public string $command = '';
25+
2526
public array $commandInput = [];
27+
2628
public ?array $currentPrompt = null;
29+
2730
public string $output = '';
31+
2832
public bool $isComplete = false;
33+
2934
public ?string $error = null;
35+
3036
public array $answers = [];
37+
3138
public array $data = [];
3239

3340
protected PromptResponseStore $responseStore;
@@ -47,9 +54,9 @@ public function mount(string $command = '', array $commandInput = []): void
4754
$this->currentPrompt = null;
4855
$this->output = '';
4956
$this->error = null;
50-
57+
5158
$this->responseStore->resetCounter();
52-
59+
5360
if ($command) {
5461
$this->runCommand();
5562
}
@@ -62,23 +69,24 @@ protected function runCommand(): void
6269

6370
try {
6471
$this->responseStore->resetCounter();
65-
72+
6673
foreach ($this->answers as $promptId => $answer) {
6774
$this->responseStore->set($promptId, $answer);
6875
}
69-
76+
7077
app()->instance('moox.prompts.response_store', $this->responseStore);
7178

7279
$commandInstance = app(\Illuminate\Contracts\Console\Kernel::class)
7380
->all()[$this->command] ?? null;
7481

75-
if (!$commandInstance) {
82+
if (! $commandInstance) {
7683
$this->error = "Command nicht gefunden: {$this->command}";
84+
7785
return;
7886
}
7987

8088
$commandInstance->setLaravel(app());
81-
$output = new BufferedOutput();
89+
$output = new BufferedOutput;
8290

8391
$outputStyle = new OutputStyle(
8492
new ArrayInput($this->commandInput),
@@ -103,7 +111,7 @@ protected function runCommand(): void
103111
if ($promptId && isset($this->answers[$promptId])) {
104112
$value = $this->answers[$promptId];
105113
if ($prompt['method'] === 'multiselect') {
106-
if (!is_array($value)) {
114+
if (! is_array($value)) {
107115
if ($value === true) {
108116
$params = $prompt['params'] ?? [];
109117
$options = $params[1] ?? [];
@@ -124,12 +132,12 @@ protected function runCommand(): void
124132

125133
public function submitPrompt(): void
126134
{
127-
if (!$this->currentPrompt) {
135+
if (! $this->currentPrompt) {
128136
return;
129137
}
130138

131139
$promptId = $this->currentPrompt['id'] ?? null;
132-
if (!$promptId) {
140+
if (! $promptId) {
133141
return;
134142
}
135143

@@ -138,9 +146,9 @@ public function submitPrompt(): void
138146
$params = $this->currentPrompt['params'] ?? [];
139147
$options = $params[1] ?? [];
140148
$answer = [];
141-
149+
142150
foreach (array_keys($options) as $key) {
143-
$checkboxId = $promptId . '_' . $key;
151+
$checkboxId = $promptId.'_'.$key;
144152
if (isset($this->data[$checkboxId]) && $this->data[$checkboxId] === true) {
145153
$answer[] = $key;
146154
}
@@ -152,9 +160,9 @@ public function submitPrompt(): void
152160
if ($this->currentPrompt['method'] !== 'multiselect' && ($answer === null || ($answer === '' && $this->currentPrompt['method'] !== 'confirm'))) {
153161
$allRequestData = request()->all();
154162
$updates = data_get($allRequestData, 'components.0.updates', []);
155-
163+
156164
if (is_array($updates) || is_object($updates)) {
157-
$updateKey = 'data.' . $promptId;
165+
$updateKey = 'data.'.$promptId;
158166
if (isset($updates[$updateKey])) {
159167
$answer = $updates[$updateKey];
160168
}
@@ -163,7 +171,7 @@ public function submitPrompt(): void
163171
}
164172
if ($answer === null) {
165173
foreach ($updates as $key => $value) {
166-
if (str_ends_with($key, '.' . $promptId) || $key === $promptId) {
174+
if (str_ends_with($key, '.'.$promptId) || $key === $promptId) {
167175
$answer = $value;
168176
break;
169177
}
@@ -181,13 +189,13 @@ public function submitPrompt(): void
181189
$answer = false;
182190
}
183191

184-
if (($answer === null || $answer === '' || ($this->currentPrompt['method'] === 'multiselect' && !is_array($answer))) && $this->currentPrompt['method'] !== 'confirm') {
192+
if (($answer === null || $answer === '' || ($this->currentPrompt['method'] === 'multiselect' && ! is_array($answer))) && $this->currentPrompt['method'] !== 'confirm') {
185193
try {
186194
$data = $this->form->getState();
187195
$answer = $data[$promptId] ?? null;
188-
196+
189197
if ($this->currentPrompt['method'] === 'multiselect') {
190-
if (!is_array($answer)) {
198+
if (! is_array($answer)) {
191199
if ($answer === true) {
192200
$params = $this->currentPrompt['params'] ?? [];
193201
$options = $params[1] ?? [];
@@ -201,25 +209,25 @@ public function submitPrompt(): void
201209
return;
202210
}
203211
}
204-
212+
205213
if (($answer === null || $answer === '') && $this->currentPrompt['method'] === 'select') {
206214
$params = $this->currentPrompt['params'] ?? [];
207215
$options = $params[1] ?? [];
208-
if (!empty($options)) {
216+
if (! empty($options)) {
209217
$answer = array_key_first($options);
210218
}
211219
}
212-
220+
213221
if ($this->currentPrompt['method'] === 'confirm') {
214222
if ($answer === null) {
215223
return;
216224
}
217225
} elseif ($answer === null || $answer === '') {
218226
return;
219227
}
220-
228+
221229
if ($this->currentPrompt['method'] === 'multiselect') {
222-
if (!is_array($answer)) {
230+
if (! is_array($answer)) {
223231
if ($answer === true) {
224232
$params = $this->currentPrompt['params'] ?? [];
225233
$options = $params[1] ?? [];
@@ -230,18 +238,18 @@ public function submitPrompt(): void
230238
$answer = [];
231239
}
232240
}
233-
234-
if (!is_array($answer)) {
241+
242+
if (! is_array($answer)) {
235243
$answer = [];
236244
}
237245
}
238-
246+
239247
if ($this->currentPrompt['method'] === 'confirm') {
240-
if (!is_bool($answer)) {
248+
if (! is_bool($answer)) {
241249
$answer = (bool) $answer;
242250
}
243251
}
244-
252+
245253
$this->answers[$promptId] = $answer;
246254
$this->currentPrompt = null;
247255
$this->runCommand();
@@ -264,7 +272,7 @@ public function form(\Filament\Schemas\Schema $schema): \Filament\Schemas\Schema
264272

265273
protected function getFormSchema(): array
266274
{
267-
if ($this->isComplete || !$this->currentPrompt) {
275+
if ($this->isComplete || ! $this->currentPrompt) {
268276
return [];
269277
}
270278

@@ -278,7 +286,7 @@ protected function getFormSchema(): array
278286

279287
$field = $this->createFieldFromPrompt($promptId, $method, $params);
280288

281-
if (!$field) {
289+
if (! $field) {
282290
return [];
283291
}
284292

@@ -291,23 +299,23 @@ protected function createMultiselectFields(string $promptId, array $params): arr
291299
$required = ($params[3] ?? false) !== false;
292300
$defaultValue = $this->answers[$promptId] ?? null;
293301
$options = $params[1] ?? [];
294-
302+
295303
$fields = [];
296-
297-
$fields[] = Placeholder::make($promptId . '_label')
304+
305+
$fields[] = Placeholder::make($promptId.'_label')
298306
->label($label)
299307
->content('');
300-
308+
301309
foreach ($options as $key => $optionLabel) {
302-
$checkboxId = $promptId . '_' . $key;
310+
$checkboxId = $promptId.'_'.$key;
303311
$isChecked = is_array($defaultValue) && in_array($key, $defaultValue);
304-
312+
305313
$fields[] = Checkbox::make($checkboxId)
306314
->label($optionLabel)
307315
->default($isChecked)
308316
->live(onBlur: false);
309317
}
310-
318+
311319
return $fields;
312320
}
313321

@@ -317,7 +325,7 @@ protected function createFieldFromPrompt(string $promptId, string $method, array
317325
$required = ($params[3] ?? false) !== false;
318326
$defaultValue = $this->answers[$promptId] ?? null;
319327

320-
return match($method) {
328+
return match ($method) {
321329
'text' => TextInput::make($promptId)
322330
->label($label)
323331
->placeholder($params[1] ?? '')

packages/prompts/src/Filament/Pages/RunCommandPage.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66

77
class RunCommandPage extends Page
88
{
9-
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-command-line';
10-
9+
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-command-line';
10+
1111
protected string $view = 'moox-prompts::filament.pages.run-command';
12-
12+
1313
protected static ?string $navigationLabel = 'Command Runner';
14-
14+
1515
protected static ?string $title = 'Command Runner';
16-
17-
protected static string | \UnitEnum | null $navigationGroup = 'System';
18-
16+
17+
protected static string|\UnitEnum|null $navigationGroup = 'System';
18+
1919
protected static ?int $navigationSort = 100;
2020

2121
public string $selectedCommand = '';
22+
2223
public array $availableCommands = [];
24+
2325
public bool $started = false;
2426

2527
public function mount(): void
@@ -43,23 +45,23 @@ public function resetCommand(): void
4345
protected function getAvailableCommands(): array
4446
{
4547
$allowedCommands = config('prompts.allowed_commands', []);
46-
48+
4749
if (empty($allowedCommands)) {
4850
return [];
4951
}
50-
52+
5153
$allCommands = app(\Illuminate\Contracts\Console\Kernel::class)->all();
52-
54+
5355
$available = [];
5456
foreach ($allowedCommands as $commandName) {
5557
if (isset($allCommands[$commandName])) {
5658
$command = $allCommands[$commandName];
5759
$available[$commandName] = $command->getDescription() ?: $commandName;
5860
}
5961
}
60-
62+
6163
ksort($available);
62-
64+
6365
return $available;
6466
}
6567
}

packages/prompts/src/Filament/PromptsPlugin.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ public static function get(): static
3535
return filament(app(static::class)->getId());
3636
}
3737
}
38-

packages/prompts/src/PromptsServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use Moox\Core\MooxServiceProvider;
66
use Moox\Prompts\Support\CliPromptRuntime;
7-
use Moox\Prompts\Support\PromptRuntime;
87
use Moox\Prompts\Support\PromptResponseStore;
8+
use Moox\Prompts\Support\PromptRuntime;
99
use Moox\Prompts\Support\WebPromptRuntime;
1010
use Spatie\LaravelPackageTools\Package;
1111

packages/prompts/src/Support/PendingPromptsException.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ public function getPrompt(): ?array
2424
return $this->prompts[0] ?? null;
2525
}
2626
}
27-

packages/prompts/src/Support/PromptResponseStore.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class PromptResponseStore
66
{
77
protected array $responses = [];
8+
89
protected int $promptCounter = 0;
910

1011
public function set(string $promptId, mixed $value): void
@@ -35,7 +36,7 @@ public function all(): array
3536

3637
public function getNextPromptId(string $method): string
3738
{
38-
return 'prompt_' . (++$this->promptCounter);
39+
return 'prompt_'.(++$this->promptCounter);
3940
}
4041

4142
public function resetCounter(): void

0 commit comments

Comments
 (0)