Skip to content

Commit 611ba7b

Browse files
committed
wip
1 parent fba785a commit 611ba7b

File tree

13 files changed

+637
-325
lines changed

13 files changed

+637
-325
lines changed

packages/prompts/README.md

Lines changed: 111 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,116 @@
11
# Moox Prompts
22

3-
CLI-kompatible Prompts für Laravel Artisan Commands.
4-
5-
## Übersicht
6-
7-
Dieses Package bietet eine einfache Proxy-Implementierung für Laravel Prompts. Es ermöglicht es, die gleichen Helper-Funktionen wie Laravel Prompts zu verwenden, mit der Möglichkeit, später Web-Funktionalität hinzuzufügen.
8-
9-
## Features
10-
11-
- ✅ Alle Laravel Prompt-Typen unterstützt (`text`, `select`, `multiselect`, `confirm`, etc.)
12-
- ✅ Identische API wie Laravel Prompts
13-
14-
## Installation
15-
16-
```bash
17-
composer require moox/prompts
18-
```
19-
20-
## Verwendung
21-
22-
### In Commands
23-
24-
Verwende die gleichen Helper-Funktionen wie in Laravel Prompts:
25-
26-
```php
27-
use function Moox\Prompts\text;
28-
use function Moox\Prompts\select;
29-
use function Moox\Prompts\confirm;
30-
use function Moox\Prompts\form;
31-
32-
public function handle()
33-
{
34-
// Einzelne Prompts
35-
$name = text('What is your name?');
36-
$package = select('Which package?', ['moox/core', 'moox/user']);
37-
$confirm = confirm('Are you sure?');
38-
39-
// FormBuilder
40-
$result = form()
41-
->text('Name?')
42-
->select('Package?', ['moox/core', 'moox/user'])
43-
->submit();
44-
45-
// Command-Logik...
46-
}
47-
```
48-
49-
## Architektur
50-
51-
Das Package besteht aus:
52-
53-
- **PromptRuntime**: Interface für Prompt-Implementierungen
54-
- **CliPromptRuntime**: CLI-Implementierung (delegiert an Laravel Prompts)
55-
- **functions.php**: Globale Helper-Funktionen
56-
- **PromptsServiceProvider**: Registriert Services
3+
CLI- und Web-kompatible Prompts für Laravel Artisan Commands – mit einem Flow, der im Browser Schritt für Schritt weiterläuft.
4+
5+
## Wie muss ein Flow-Command aussehen?
6+
7+
Damit ein Command sowohl in der CLI als auch im Web korrekt als Flow funktioniert, müssen nur diese Regeln erfüllt sein:
8+
9+
- **Von `FlowCommand` erben**
10+
```php
11+
use Moox\Prompts\Support\FlowCommand;
12+
use function Moox\Prompts\text;
13+
use function Moox\Prompts\select;
14+
15+
class ProjectSetupCommand extends FlowCommand
16+
{
17+
protected $signature = 'prompts:project-setup';
18+
protected $description = 'Projekt Setup Wizard (CLI & Web)';
19+
```
20+
21+
- **State als Properties ablegen** (werden im Web automatisch zwischen Steps gespeichert)
22+
```php
23+
public ?string $environment = null;
24+
public ?string $projectName = null;
25+
```
26+
27+
- **Steps über `promptFlowSteps()` definieren** – Reihenfolge = Flow-Reihenfolge
28+
```php
29+
public function promptFlowSteps(): array
30+
{
31+
return [
32+
'stepIntro',
33+
'stepEnvironment',
34+
'stepProjectName',
35+
'stepSummary',
36+
];
37+
}
38+
```
39+
40+
- **Jeder Step ist eine `public function stepXyz(): void`** – idealerweise **ein Prompt pro Step**
41+
```php
42+
public function stepIntro(): void
43+
{
44+
$this->info('=== Projekt Setup ===');
45+
}
46+
47+
public function stepEnvironment(): void
48+
{
49+
$this->environment = select(
50+
label: 'Welche Umgebung konfigurierst du?',
51+
options: [
52+
'local' => 'Local',
53+
'staging' => 'Staging',
54+
'production' => 'Production',
55+
],
56+
default: 'local',
57+
);
58+
}
59+
60+
public function stepProjectName(): void
61+
{
62+
$this->projectName = text(
63+
label: 'Wie heißt dein Projekt?',
64+
placeholder: 'z.B. MyCoolApp',
65+
validate: 'required|min:3',
66+
required: true,
67+
);
68+
}
69+
70+
public function stepSummary(): void
71+
{
72+
$this->info('--- Zusammenfassung ---');
73+
$this->line('Projekt: '.$this->projectName);
74+
$this->line('Environment: '.$this->environment);
75+
}
76+
}
77+
```
78+
79+
- **Optionale Steps** kannst du einfach mit einem Guard am Anfang überspringen:
80+
```php
81+
public array $features = [];
82+
83+
public function stepLoggingLevel(): void
84+
{
85+
if (! in_array('logging', $this->features, true)) {
86+
return; // Step wird übersprungen
87+
}
88+
89+
// Prompt …
90+
}
91+
```
92+
93+
- **Andere Artisan-Commands aufrufen** – verwende im Flow immer `$this->call()` statt `Artisan::call()`, damit der Output auch im Web angezeigt wird:
94+
```php
95+
public function stepPublishConfig(): void
96+
{
97+
$shouldPublish = confirm(
98+
label: 'Möchtest du die Config jetzt veröffentlichen?',
99+
default: true,
100+
);
101+
102+
if (! $shouldPublish) {
103+
return;
104+
}
105+
106+
$this->call('vendor:publish', [
107+
'--tag' => 'moox-prompts-config',
108+
]);
109+
}
110+
```
111+
112+
Mehr ist im Command nicht nötig – keine speziellen Flow-Methoden, keine eigene Persistenz.
113+
Der Rest (CLI/Web-Unterschied, State, Web-Oberfläche) wird komplett vom Package übernommen.
57114

58115
## License
59116

packages/prompts/config/prompts.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
*/
3131

3232
'allowed_commands' => [
33-
'prompts:test-flow',
34-
'prompts:publish-news-config',
33+
'prompts:project-setup',
3534
// Add more commands here as needed
3635
],
3736

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,60 @@
11
<x-filament-panels::page>
2-
@if(!$started)
3-
<x-filament::section>
4-
<x-slot name="heading">
5-
Command auswählen
6-
</x-slot>
7-
8-
@if(empty($availableCommands))
9-
<p style="color: #6b7280;">Keine Commands verfügbar. Bitte konfigurieren Sie die erlaubten Commands in der Konfiguration.</p>
10-
@else
11-
<form wire:submit="startCommand">
12-
<x-filament::input.wrapper>
13-
<x-filament::input.select wire:model="selectedCommand" required>
14-
<option value="">-- Command auswählen --</option>
15-
@foreach($availableCommands as $commandName => $description)
16-
<option value="{{ $commandName }}">{{ $commandName }} - {{ $description }}</option>
17-
@endforeach
18-
</x-filament::input.select>
19-
</x-filament::input.wrapper>
20-
21-
<div style="margin-top: 1rem;">
22-
<x-filament::button type="submit" color="primary">
23-
Command starten
24-
</x-filament::button>
25-
</div>
26-
</form>
27-
@endif
28-
</x-filament::section>
2+
@if (!$started)
3+
<div>
4+
<x-filament::section>
5+
@if (empty($availableCommands))
6+
<p style="font-size: 0.875rem; color: #6b7280;">
7+
Keine Commands verfügbar. Bitte konfiguriere die erlaubten Commands in der
8+
<code style="padding: 0.125rem 0.25rem; background-color: #f3f4f6; border-radius: 0.25rem; font-size: 0.75rem;">
9+
config/prompts.php
10+
</code>.
11+
</p>
12+
@else
13+
<form wire:submit="startCommand" style="display: flex; flex-direction: column; gap: 1.25rem; margin-top: 0.5rem;">
14+
<div style="display: flex; flex-direction: column; gap: 0.25rem; max-width: 480px;">
15+
<label style="font-size: 0.875rem;">
16+
Command
17+
</label>
18+
19+
<x-filament::input.wrapper>
20+
<x-filament::input.select wire:model="selectedCommand" required>
21+
<option value="">Bitte Command auswählen …</option>
22+
@foreach ($availableCommands as $commandName => $description)
23+
<option value="{{ $commandName }}">
24+
{{ $commandName }}{{ $description }}
25+
</option>
26+
@endforeach
27+
</x-filament::input.select>
28+
</x-filament::input.wrapper>
29+
</div>
30+
31+
<div style="display: flex; flex-direction: column; align-items: flex-start; gap: 0.5rem; max-width: 640px;">
32+
<p style="font-size: 0.875rem; color: #6b7280; margin: 0;">
33+
Nur Commands aus der Konfiguration sind hier sichtbar.
34+
</p>
35+
36+
<x-filament::button type="submit" color="primary">
37+
Command starten
38+
</x-filament::button>
39+
</div>
40+
</form>
41+
@endif
42+
</x-filament::section>
43+
</div>
2944
@else
30-
@livewire('moox-prompts.filament.components.run-command-component', [
31-
'command' => $selectedCommand,
32-
'commandInput' => []
33-
], key('run-command-' . $selectedCommand))
34-
35-
<div style="margin-top: 1rem;">
36-
<x-filament::button wire:click="resetCommand" color="gray">
37-
Zurück
38-
</x-filament::button>
45+
<div>
46+
<x-filament::section>
47+
@livewire('moox-prompts.filament.components.run-command-component', [
48+
'command' => $selectedCommand,
49+
'commandInput' => [],
50+
], key('run-command-' . $selectedCommand))
51+
</x-filament::section>
52+
53+
<div style="margin-top: 1rem;">
54+
<x-filament::button wire:click="resetCommand" color="gray">
55+
Zurück zur Command-Auswahl
56+
</x-filament::button>
57+
</div>
3958
</div>
4059
@endif
4160
</x-filament-panels::page>

0 commit comments

Comments
 (0)