-
Notifications
You must be signed in to change notification settings - Fork 16
/
args.php
65 lines (56 loc) 路 1.87 KB
/
args.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
<?php
namespace args;
use Castor\Attribute\AsArgument;
use Castor\Attribute\AsOption;
use Castor\Attribute\AsRawTokens;
use Castor\Attribute\AsTask;
use Symfony\Component\Console\Completion\CompletionInput;
use function Castor\io;
/**
* @param string[] $argument2
*/
#[AsTask(description: 'Dumps all arguments and options, with custom configuration')]
function args(
#[AsArgument(description: 'This is a required argument without any typing', suggestedValues: ['hello', 'bonjour', 'hola'])]
$word,
#[AsArgument(name: 'array-of-people', description: 'This is an optional array argument')]
array $argument2 = ['world', 'PHP community'],
#[AsOption(description: 'This with an option with an optional value')]
string $option = 'default value',
#[AsOption(description: 'This a an option without value in CLI')]
bool $dryRun = false,
): void {
var_dump(\func_get_args());
}
#[AsTask(description: 'Dumps all arguments and options, without configuration')]
function another_args(
string $required,
int $test2 = 1
): void {
io()->writeln($required . ' ' . $test2);
}
/**
* @param string[] $rawTokens
*/
#[AsTask(description: 'Dumps all arguments and options, without configuration nor validation', ignoreValidationErrors: true)]
function passthru(#[AsRawTokens] array $rawTokens): void
{
var_dump($rawTokens);
}
#[AsTask(description: 'Provides autocomplete for an argument')]
function autocomplete_argument(
#[AsArgument(name: 'argument', description: 'This is an argument with autocompletion', autocomplete: 'args\get_argument_autocompletion')]
string $argument,
): void {
var_dump(\func_get_args());
}
/** @return string[] */
function get_argument_autocompletion(CompletionInput $input): array
{
// You can search for a file on the filesystem, make a network call, etc.
return [
'foo',
'bar',
'baz',
];
}