Skip to content

Commit 8646544

Browse files
committed
Improve missing command detection and plugin handling
1 parent 3b2e8aa commit 8646544

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

devtools/cli/src/main/java/io/quarkus/cli/QuarkusCli.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.List;
1111
import java.util.Map;
1212
import java.util.Optional;
13+
import java.util.Set;
1314
import java.util.concurrent.Callable;
1415
import java.util.function.Supplier;
1516
import java.util.stream.Collectors;
@@ -66,6 +67,8 @@ public class QuarkusCli implements QuarkusApplication, Callable<Integer> {
6667
System.setProperty("picocli.endofoptions.description", "End of command line options.");
6768
}
6869

70+
private static final Set<String> CATCH_ALL_COMMANDS = Set.of("create", "image", "extension", "ext", "plugin", "plug");
71+
6972
@Inject
7073
CommandLine.IFactory factory;
7174

@@ -125,7 +128,7 @@ public int run(String... args) throws Exception {
125128
pluginCommandFactory.populateCommands(cmd, plugins);
126129
missingCommand.filter(m -> !plugins.containsKey(m)).ifPresent(m -> {
127130
try {
128-
output.info("Command %s is not available, looking for available plugins ...", m);
131+
output.info("Unable to match command `%s`, looking for available plugins...", m);
129132
Map<String, Plugin> installable = pluginManager.getInstallablePlugins();
130133
if (installable.containsKey(m)) {
131134
Plugin candidate = installable.get(m);
@@ -140,10 +143,10 @@ public int run(String... args) throws Exception {
140143
pluginCommandFactory.populateCommands(cmd, plugins);
141144
}
142145
} else {
143-
output.error("Command %s is missing and can't be installed.", m);
146+
output.error("Unable to match command `%s` and a corresponding plugin couldn't be installed.", m);
144147
}
145148
} catch (Exception e) {
146-
output.error("Command %s is missing and can't be installed.", m);
149+
output.error("Unable to match command `%s` and a corresponding plugin couldn't be installed.", m);
147150
}
148151
});
149152
} catch (MutuallyExclusiveArgsException e) {
@@ -166,6 +169,12 @@ public Optional<String> checkMissingCommand(CommandLine root, String[] args) {
166169

167170
try {
168171
ParseResult currentParseResult = root.parseArgs(args);
172+
173+
// some commands are catch all and they will match always
174+
if (CATCH_ALL_COMMANDS.contains(currentParseResult.commandSpec().name())) {
175+
return Optional.empty();
176+
}
177+
169178
StringBuilder missingCommand = new StringBuilder();
170179

171180
do {
@@ -188,6 +197,11 @@ public Optional<String> checkMissingCommand(CommandLine root, String[] args) {
188197

189198
return Optional.empty();
190199
} catch (UnmatchedArgumentException e) {
200+
// the first element was matched so it's not missing
201+
if (e.getCommandLine() != root) {
202+
return Optional.empty();
203+
}
204+
191205
return Optional.of(args[0]);
192206
} catch (Exception e) {
193207
// For any other exceptions (e.g. MissingParameterException), we should just ignore.

0 commit comments

Comments
 (0)