11<?php
2+ require __DIR__ . '/vendor/autoload.php ' ;
23
34function invoke_wp_cli ( $ cmd , $ app ) {
45 $ cmd .= ' --path= ' . escapeshellarg ( $ app ['path ' ] );
@@ -15,6 +16,12 @@ function invoke_wp_cli( $cmd, $app ) {
1516 return json_decode ( $ json , true );
1617}
1718
19+ function render ( $ path , $ binding ) {
20+ $ m = new Mustache_Engine ;
21+ $ template = file_get_contents ( __DIR__ . "/_templates/ $ path " );
22+ return $ m ->render ( $ template , $ binding );
23+ }
24+
1825desc ( 'Generate a list of commands with all accepted arguments on STDOUT. ' );
1926task ( 'syn-list ' , function ( $ app ) {
2027 function generate_synopsis ( $ command , $ path = '' ) {
@@ -35,22 +42,9 @@ function generate_synopsis( $command, $path = '' ) {
3542desc ( 'Update the /commands/ page. ' );
3643task ( 'cmd-list ' , function ( $ app ) {
3744 $ wp = invoke_wp_cli ( 'wp --cmd-dump ' , $ app );
45+ $ wp ['version ' ] = $ app ['version ' ];
3846
39- $ out = '' ;
40-
41- foreach ( $ wp ['subcommands ' ] as $ command ) {
42- $ url = "https://github.com/wp-cli/wp-cli/blob/ {$ app ['version ' ]}/php/commands/ {$ command ['name ' ]}.php " ;
43-
44- $ out .= <<<EOB
45- <tr>
46- <td><a href=" {$ url }"> {$ command ['name ' ]}</a></td>
47- <td> {$ command ['description ' ]}</td>
48- </tr>
49-
50- EOB ;
51- }
52-
53- file_put_contents ( '_includes/cmd-list.html ' , $ out );
47+ file_put_contents ( '_includes/cmd-list.html ' , render ( 'cmd-list.mustache ' , $ wp ) );
5448});
5549
5650desc ( 'Update the /config/ page. ' );
@@ -64,15 +58,15 @@ function generate_synopsis( $command, $path = '' ) {
6458 continue ;
6559
6660 if ( false !== $ details ['file ' ] ) {
67- $ config = "$ key: " . htmlspecialchars ( $ details ['file ' ] ) ;
61+ $ config = "$ key: " . $ details ['file ' ];
6862 } else {
6963 $ config = '' ;
7064 }
7165
7266 if ( false !== $ details ['runtime ' ] ) {
7367 $ flag = ( true === $ details ['runtime ' ] )
7468 ? "--[no-] $ key "
75- : "-- $ key " . htmlspecialchars ( $ details ['runtime ' ] ) ;
69+ : "-- $ key " . $ details ['runtime ' ];
7670 } else {
7771 $ flag = '' ;
7872 }
@@ -81,15 +75,7 @@ function generate_synopsis( $command, $path = '' ) {
8175
8276 $ description = $ details ['desc ' ];
8377
84- $ out .= <<<EOB
85- <tr>
86- <td><code> $ config</code></td>
87- <td><code> $ flag</code></td>
88- <td><code> $ default</code></td>
89- <td> $ description</td>
90- </tr>
91-
92- EOB ;
78+ $ out .= render ( 'config.mustache ' , compact ( 'config ' , 'flag ' , 'default ' , 'description ' ) );
9379 }
9480
9581 file_put_contents ( '_includes/param-list.html ' , $ out );
0 commit comments