|
1 | 1 | # Moox Prompts |
2 | 2 |
|
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. |
57 | 114 |
|
58 | 115 | ## License |
59 | 116 |
|
|
0 commit comments