-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathhelpers.php
259 lines (233 loc) · 7.89 KB
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php
namespace Laravel\Prompts;
use Closure;
use Illuminate\Support\Collection;
if (! function_exists('\Laravel\Prompts\text')) {
/**
* Prompt the user for text input.
*/
function text(string $label, string $placeholder = '', string $default = '', bool|string $required = false, mixed $validate = null, string $hint = '', ?Closure $transform = null): string
{
return (new TextPrompt(...get_defined_vars()))->prompt();
}
}
if (! function_exists('\Laravel\Prompts\textarea')) {
/**
* Prompt the user for multiline text input.
*/
function textarea(string $label, string $placeholder = '', string $default = '', bool|string $required = false, mixed $validate = null, string $hint = '', int $rows = 5, ?Closure $transform = null): string
{
return (new TextareaPrompt(...get_defined_vars()))->prompt();
}
}
if (! function_exists('\Laravel\Prompts\password')) {
/**
* Prompt the user for input, hiding the value.
*/
function password(string $label, string $placeholder = '', bool|string $required = false, mixed $validate = null, string $hint = '', ?Closure $transform = null): string
{
return (new PasswordPrompt(...get_defined_vars()))->prompt();
}
}
if (! function_exists('\Laravel\Prompts\select')) {
/**
* Prompt the user to select an option.
*
* @param array<int|string, string>|Collection<int|string, string> $options
* @param true|string $required
*/
function select(string $label, array|Collection $options, int|string|null $default = null, int $scroll = 5, mixed $validate = null, string $hint = '', bool|string $required = true, ?Closure $transform = null): int|string
{
return (new SelectPrompt(...get_defined_vars()))->prompt();
}
}
if (! function_exists('\Laravel\Prompts\multiselect')) {
/**
* Prompt the user to select multiple options.
*
* @param array<int|string, string>|Collection<int|string, string> $options
* @param array<int|string>|Collection<int, int|string> $default
* @return array<int|string>
*/
function multiselect(string $label, array|Collection $options, array|Collection $default = [], int $scroll = 5, bool|string $required = false, mixed $validate = null, string $hint = 'Use the space bar to select options.', ?Closure $transform = null): array
{
return (new MultiSelectPrompt(...get_defined_vars()))->prompt();
}
}
if (! function_exists('\Laravel\Prompts\confirm')) {
/**
* Prompt the user to confirm an action.
*/
function confirm(string $label, bool $default = true, string $yes = 'Yes', string $no = 'No', bool|string $required = false, mixed $validate = null, string $hint = '', ?Closure $transform = null): bool
{
return (new ConfirmPrompt(...get_defined_vars()))->prompt();
}
}
if (! function_exists('\Laravel\Prompts\pause')) {
/**
* Prompt the user to continue or cancel after pausing.
*/
function pause(string $message = 'Press enter to continue...'): bool
{
return (new PausePrompt(...get_defined_vars()))->prompt();
}
}
if (! function_exists('\Laravel\Prompts\clear')) {
/**
* Clear the terminal.
*/
function clear(): void
{
(new Clear)->display();
}
}
if (! function_exists('\Laravel\Prompts\suggest')) {
/**
* Prompt the user for text input with auto-completion.
*
* @param array<string>|Collection<int, string>|Closure(string): array<string> $options
*/
function suggest(string $label, array|Collection|Closure $options, string $placeholder = '', string $default = '', int $scroll = 5, bool|string $required = false, mixed $validate = null, string $hint = '', ?Closure $transform = null): string
{
return (new SuggestPrompt(...get_defined_vars()))->prompt();
}
}
if (! function_exists('\Laravel\Prompts\search')) {
/**
* Allow the user to search for an option.
*
* @param Closure(string): array<int|string, string> $options
* @param true|string $required
*/
function search(string $label, Closure $options, string $placeholder = '', int $scroll = 5, mixed $validate = null, string $hint = '', bool|string $required = true, ?Closure $transform = null): int|string
{
return (new SearchPrompt(...get_defined_vars()))->prompt();
}
}
if (! function_exists('\Laravel\Prompts\multisearch')) {
/**
* Allow the user to search for multiple option.
*
* @param Closure(string): array<int|string, string> $options
* @return array<int|string>
*/
function multisearch(string $label, Closure $options, string $placeholder = '', int $scroll = 5, bool|string $required = false, mixed $validate = null, string $hint = 'Use the space bar to select options.', ?Closure $transform = null): array
{
return (new MultiSearchPrompt(...get_defined_vars()))->prompt();
}
}
if (! function_exists('\Laravel\Prompts\spin')) {
/**
* Render a spinner while the given callback is executing.
*
* @template TReturn of mixed
*
* @param \Closure(): TReturn $callback
* @return TReturn
*/
function spin(Closure $callback, string $message = ''): mixed
{
return (new Spinner($message))->spin($callback);
}
}
if (! function_exists('\Laravel\Prompts\note')) {
/**
* Display a note.
*/
function note(string $message, ?string $type = null): void
{
(new Note($message, $type))->display();
}
}
if (! function_exists('\Laravel\Prompts\error')) {
/**
* Display an error.
*/
function error(string $message): void
{
(new Note($message, 'error'))->display();
}
}
if (! function_exists('\Laravel\Prompts\warning')) {
/**
* Display a warning.
*/
function warning(string $message): void
{
(new Note($message, 'warning'))->display();
}
}
if (! function_exists('\Laravel\Prompts\alert')) {
/**
* Display an alert.
*/
function alert(string $message): void
{
(new Note($message, 'alert'))->display();
}
}
if (! function_exists('\Laravel\Prompts\info')) {
/**
* Display an informational message.
*/
function info(string $message): void
{
(new Note($message, 'info'))->display();
}
}
if (! function_exists('\Laravel\Prompts\intro')) {
/**
* Display an introduction.
*/
function intro(string $message): void
{
(new Note($message, 'intro'))->display();
}
}
if (! function_exists('\Laravel\Prompts\outro')) {
/**
* Display a closing message.
*/
function outro(string $message): void
{
(new Note($message, 'outro'))->display();
}
}
if (! function_exists('\Laravel\Prompts\table')) {
/**
* Display a table.
*
* @param array<int, string|array<int, string>>|Collection<int, string|array<int, string>> $headers
* @param array<int, array<int, string>>|Collection<int, array<int, string>> $rows
*/
function table(array|Collection $headers = [], array|Collection|null $rows = null): void
{
(new Table($headers, $rows))->display();
}
}
if (! function_exists('\Laravel\Prompts\progress')) {
/**
* Display a progress bar.
*
* @template TSteps of iterable<mixed>|int
* @template TReturn
*
* @param TSteps $steps
* @param ?Closure((TSteps is int ? int : value-of<TSteps>), Progress<TSteps>): TReturn $callback
* @return ($callback is null ? Progress<TSteps> : array<TReturn>)
*/
function progress(string $label, iterable|int $steps, ?Closure $callback = null, string $hint = ''): array|Progress
{
$progress = new Progress($label, $steps, $hint);
if ($callback !== null) {
return $progress->map($callback);
}
return $progress;
}
}
if (! function_exists('\Laravel\Prompts\form')) {
function form(): FormBuilder
{
return new FormBuilder;
}
}