forked from wp-cli/wp-cli.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhakefile.php
More file actions
98 lines (74 loc) · 2.17 KB
/
Phakefile.php
File metadata and controls
98 lines (74 loc) · 2.17 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
<?php
function invoke_wp_cli( $cmd, $app ) {
$cmd .= ' --path=' . escapeshellarg( $app['path'] );
ob_start();
system( $cmd, $return_code );
$json = ob_get_clean();
if ( $return_code ) {
echo "wp-cli returned error code: $return_code\n";
exit(1);
}
return json_decode( $json, true );
}
desc( 'Generate a list of commands with all accepted arguments on STDOUT.' );
task( 'syn-list', function( $app ) {
function generate_synopsis( $command, $path = '' ) {
$full_path = $path . ' ' . $command['name'];
if ( !isset( $command['subcommands'] ) ) {
echo $full_path . ' ' . $command['synopsis'] . "\n";
} else {
foreach ( $command['subcommands'] as $subcommand ) {
generate_synopsis( $subcommand, $full_path );
}
}
}
generate_synopsis( invoke_wp_cli( 'wp --cmd-dump', $app ) );
});
desc( 'Update the /commands/ page.' );
task( 'cmd-list', function( $app ) {
$wp = invoke_wp_cli( 'wp --cmd-dump', $app );
$out = '';
foreach ( $wp['subcommands'] as $command ) {
$out .= <<<EOB
<tr>
<td><a href="https://github.com/wp-cli/wp-cli/blob/master/php/commands/{$command['name']}.php">{$command['name']}</a></td>
<td>{$command['description']}</td>
</tr>
EOB;
}
file_put_contents( '_includes/cmd-list.html', $out );
});
desc( 'Update the /config/ page.' );
task( 'param-list', function( $app ) {
$config_spec = invoke_wp_cli( 'wp --param-dump', $app );
$out = '';
foreach ( $config_spec as $key => $details ) {
if ( isset( $details['deprecated'] ) )
continue;
if ( false !== $details['file'] ) {
$config = "$key: " . htmlspecialchars( $details['file'] );
} else {
$config = '';
}
if ( false !== $details['runtime'] ) {
$flag = ( true === $details['runtime'] )
? "--[no-]$key"
: "--$key" . htmlspecialchars( $details['runtime'] );
} else {
$flag = '';
}
$default = json_encode( $details['default'] );
$description = $details['desc'];
$out .= <<<EOB
<tr>
<td><code>$config</code></td>
<td><code>$flag</code></td>
<td><code>$default</code></td>
<td>$description</td>
</tr>
EOB;
}
file_put_contents( '_includes/param-list.html', $out );
});
desc( 'Build the site.' );
task( 'default', 'cmd-list', 'param-list' );