5454import java .util .List ;
5555import java .util .concurrent .ExecutionException ;
5656import java .util .concurrent .Future ;
57+ import static java .util .logging .Level .FINE ;
5758import static java .util .logging .Level .INFO ;
5859import java .util .logging .Logger ;
5960import static java .util .logging .Level .WARNING ;
61+ import java .util .regex .Pattern ;
6062import org .netbeans .api .extexecution .ExecutionDescriptor ;
6163import org .netbeans .api .extexecution .base .input .InputProcessor ;
6264import org .netbeans .api .extexecution .base .input .InputProcessors ;
@@ -113,6 +115,8 @@ public final class WordPressCli {
113115 private final List <String > DEFAULT_PARAMS = Collections .emptyList ();
114116 private static final List <FrameworkCommand > COMMANDS_CACHE = new ArrayList <>();
115117
118+ private static final Pattern WHITESPACES_PATTERN = Pattern .compile (" +" ); // NOI18N
119+
116120 private WordPressCli (String wpCliPath ) {
117121 this .wpCliPath = wpCliPath ;
118122 }
@@ -379,6 +383,7 @@ public void updateCommands() {
379383 }
380384 long endTime = System .currentTimeMillis ();
381385 LOGGER .log (INFO , "Update Commands: took {0}ms" , endTime - startTime ); // NOI18N
386+ LOGGER .log (INFO , "{0} wp-cli commands." , COMMANDS_CACHE .size ()); // NOI18N
382387 }
383388
384389 // XXX get help later?
@@ -403,6 +408,7 @@ private void getCommands(List<String> subcommands, List<FrameworkCommand> comman
403408
404409 boolean isSubcommands = false ;
405410 boolean isFirstEmpty = false ;
411+ LOGGER .log (FINE , "{0} WP Command" , StringUtils .implode (subcommands , " " )); // NOI18N
406412 for (String line : lines ) {
407413 if (isSubcommands ) {
408414 if (StringUtils .isEmpty (line )) {
@@ -412,8 +418,13 @@ private void getCommands(List<String> subcommands, List<FrameworkCommand> comman
412418 isFirstEmpty = true ;
413419 continue ;
414420 }
421+ // XXX just ignore
422+ // in the case of long description
423+ if (line .startsWith (" " )) { // NOI18N
424+ continue ;
425+ }
415426 line = line .trim ();
416- line = line .replaceAll (" +" , " " ); // NOI18N
427+ line = WHITESPACES_PATTERN . matcher ( line ) .replaceAll (" " ); // NOI18N
417428 int indexOf = line .indexOf (" " ); // NOI18N
418429 if (indexOf == -1 ) {
419430 continue ;
@@ -428,7 +439,7 @@ private void getCommands(List<String> subcommands, List<FrameworkCommand> comman
428439 String help = getHelp (nextSubcommands );
429440 commands .add (new WordPressCliCommand (nextSubcommands .toArray (new String []{}), description , help )); // NOI18N
430441
431- // recursive
442+ // get commands recursively
432443 getCommands (nextSubcommands , commands );
433444 }
434445
0 commit comments