-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleCommand.php
More file actions
82 lines (78 loc) · 2.1 KB
/
SimpleCommand.php
File metadata and controls
82 lines (78 loc) · 2.1 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
<?php
use Idearia\WP_CLI\Command;
use WP_CLI;
class SimpleCommand extends Command
{
/**
* Prints a greeting.
*
* ## OPTIONS
*
* <name>
* : The name of the person to greet; must be at least
* 4 characters
*
* [--type=<type>]
* : Whether or not to greet the person with success or error.
* ---
* default: success
* options:
* - success
* - error
* ---
*
* ## EXAMPLES
*
* wp example hello Newman
*
* @param array $args Indexed array of positional arguments.
* @param array $assoc_args Associative array of associative arguments.
*/
public function __invoke( array $args, array $assoc_args )
{
list( $name ) = $args;
$type = $assoc_args['type'];
WP_CLI::$type( "Hello, $name!" );
}
/**
* Restrict the <name> parameter to be longer than 3 characters.
*
* @param string[] $args
* @param array<string,string> $assoc_args
* @param array<string,mixed> $options
*/
public static function validate(array $args, array $assoc_args, array $options): bool
{
$name = $args[0] ?? null;
if ( $name && strlen( $name ) <= 3 ) {
return false;
}
return true;
}
/**
* Tell the user what's going on, as soon as WP CLI starts
* thinking about executin a command
*
* @param string[] $args
* @param array<string,string> $assoc_args
* @param array<string,mixed> $options
*/
public static function before_run_command( array $args, array $assoc_args, array $options ): void
{
WP_CLI::line( "About to run command `wp " . join( " ", $args ) . "`" );
}
/**
* Tell the user what's going on, before the command is invoked
*/
public static function before_invoke(): void
{
WP_CLI::line( "Invoking command..." );
}
/**
* Tell the user what's going on, after the command is invoked
*/
public static function after_invoke(): void
{
WP_CLI::line( "All done 💪" );
}
}