Skip to content

Commit f4c23a7

Browse files
committed
Incorrect command list #67
1 parent dcb8c04 commit f4c23a7

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/org/netbeans/modules/php/wordpress/commands/WordPressCli.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@
5454
import java.util.List;
5555
import java.util.concurrent.ExecutionException;
5656
import java.util.concurrent.Future;
57+
import static java.util.logging.Level.FINE;
5758
import static java.util.logging.Level.INFO;
5859
import java.util.logging.Logger;
5960
import static java.util.logging.Level.WARNING;
61+
import java.util.regex.Pattern;
6062
import org.netbeans.api.extexecution.ExecutionDescriptor;
6163
import org.netbeans.api.extexecution.base.input.InputProcessor;
6264
import 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

Comments
 (0)