-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathIInput.php
More file actions
167 lines (153 loc) · 4.67 KB
/
Copy pathIInput.php
File metadata and controls
167 lines (153 loc) · 4.67 KB
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
<?php
declare(strict_types=1);
// SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace OCP\Console;
use InvalidArgumentException;
use OCP\AppFramework\Attribute\Consumable;
/**
* Interface that lets you retrieve the input from a command.
*
* @since 35.0.0
*/
#[Consumable(since: '35.0.0')]
interface IInput {
/**
* Returns all the given arguments merged with the default values.
*
* @return array<string|bool|int|float|array|null>
* @since 35.0.0
*/
public function getArguments(): array;
/**
* Returns the argument value for a given argument name.
*
* @throws InvalidArgumentException When argument given doesn't exist
* @since 35.0.0
*/
public function getArgument(string $name): string|bool|int|float|array|null;
/**
* Returns true if an argument exists by name or position.
* @since 35.0.0
*/
public function hasArgument(string $name): bool;
/**
* Returns all the given options merged with the default values.
*
* @return array<string|bool|int|float|array|null>
* @since 35.0.0
*/
public function getOptions(): array;
/**
* Returns the option value for a given option name.
*
* @throws InvalidArgumentException When option given doesn't exist
* @since 35.0.0
*/
public function getOption(string $name): string|bool|int|float|array|null;
/**
* Returns true if an option exists by name.
* @since 35.0.0
*/
public function hasOption(string $name): bool;
/**
* Asks the user to provide some value.
*
* ```
* $input->ask('What is your name?');
* ```
*
* You can pass the default value as the second argument so the user can hit the <Enter> key to select that value:
*
* ```
* $input->ask('Where are you from?', 'United States');
* ```
*
* In case you need to validate the given value, pass a callback validator as the third argument:
*
* ```
* $input->ask('Number of workers to start', '1', function (string $number): int {
* if (!is_numeric($number)) {
* throw new \RuntimeException('You must type a number.');
* }
*
* return (int) $number;
* });
* ```
*
* @param callable(string):mixed|null $validator
* @since 35.0.0
*/
public function ask(string $question, ?string $default = null, ?callable $validator = null): mixed;
/**
* Ask the user to provide some value but the user's input will be hidden, and it cannot define a default value.
*
* Use it when asking for sensitive information:
*
* ```
* $input->askHidden('What is your password?');
* ```
*
* In case you need to validate the given value, pass a callback validator as the second argument:
*
* ```
* $input->askHidden('What is your password?', function (string $password): string {
* if (empty($password)) {
* throw new \RuntimeException('Password cannot be empty.');
* }
*
* return $password;
* });
* ```
*
* @param callable(string):mixed|null $validator
* @since 35.0.0
*/
public function askHidden(string $question, ?callable $validator = null): mixed;
/**
* Ask a Yes/No question to the user, and it only returns true or false:
*
* ```
* $input->confirm('Restart the web server?');
* ```
*
* You can pass the default value as the second argument so the user can hit the <Enter> key to select that value:
*
* ```
* $input->confirm('Restart the web server?', true);
* ```
*
* @param string $question
* @since 35.0.0
*/
public function confirm(string $question, bool $default = true): bool;
/**
* Ask a question whose answer is constrained to the given list of valid answers:
*
* ```
* $input->choice('Select the queue to analyze', ['queue1', 'queue2', 'queue3']);
* ```
*
* You can pass the default value as the third argument so the user can hit the <Enter> key to select that value:
*
* ```
* $input->choice('Select the queue to analyze', ['queue1', 'queue2', 'queue3'], 'queue1');
* ```
*
* Choice questions display both the choice value and a numeric index, which starts from 0 by default. To use custom indices, pass an array with custom numeric keys as the choice values:
*
* ```
* $input->choice('Select the queue to analyze', [5 => 'queue1', 6 => 'queue2', 7 => 'queue3']);
* ```
*
* Finally, you can allow users to select multiple choices. To do so, users must separate each choice with a comma (e.g. typing 1, 2 will select choice 1 and 2):
*
* ```
* $input->choice('Select the queue to analyze', ['queue1', 'queue2', 'queue3'], multiSelect: true);
* ```
*
* @param array<string> $choices
* @since 35.0.0
*/
public function choice(string $question, array $choices, mixed $default = null, bool $multiSelect = false): mixed;
}