Skip to content

Commit

Permalink
Avoid using a dynamic regexp
Browse files Browse the repository at this point in the history
(cherry picked from commit 7325188)
  • Loading branch information
gsmet committed Aug 27, 2024
1 parent 87e71df commit 6fb7703
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions devtools/cli/src/main/java/io/quarkus/cli/QuarkusCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import jakarta.inject.Inject;
Expand Down Expand Up @@ -178,7 +177,7 @@ public Optional<String> checkMissingCommand(CommandLine root, String[] args) {
if (!unmatchedSubcommands.isEmpty()) {
missingCommand.append("-").append(unmatchedSubcommands.get(0));
// We don't want the root itself to be added to the result
return Optional.of(missingCommand.toString().replaceFirst(Pattern.quote(root.getCommandName() + "-"), ""));
return Optional.of(stripRootPrefix(missingCommand.toString(), root.getCommandName() + "-"));
}

currentParseResult = currentParseResult.subcommand();
Expand All @@ -195,6 +194,14 @@ public Optional<String> checkMissingCommand(CommandLine root, String[] args) {
}
}

private static String stripRootPrefix(String command, String rootPrefix) {
if (!command.startsWith(rootPrefix)) {
return command;
}

return command.substring(rootPrefix.length());
}

@Override
public Integer call() throws Exception {
output.info("%n@|bold Quarkus CLI|@ version %s", Version.clientVersion());
Expand Down

0 comments on commit 6fb7703

Please sign in to comment.