From 50610f630541feb53165deb2ebf2ea4433c2f8da Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sun, 23 Oct 2016 21:50:44 +0200 Subject: [PATCH] #979 Provide more succinct error messages for missing command entries - Show only one error message if a command section is missing altogether - Remove "commands." prefix in missing command errors --- .../HelpTranslationVerifier.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/test/java/tools/helptranslation/HelpTranslationVerifier.java b/src/test/java/tools/helptranslation/HelpTranslationVerifier.java index 2ed130fa..9cbf12b5 100644 --- a/src/test/java/tools/helptranslation/HelpTranslationVerifier.java +++ b/src/test/java/tools/helptranslation/HelpTranslationVerifier.java @@ -55,11 +55,15 @@ public class HelpTranslationVerifier { } public List getMissingCommands() { - return missingCommands; + // All entries start with "command.", so remove that + return missingCommands.stream() + .map(s -> s.substring(9)).collect(Collectors.toList()); } public List getUnknownCommands() { - return unknownCommands; + // All entries start with "command.", so remove that + return unknownCommands.stream() + .map(s -> s.substring(9)).collect(Collectors.toList()); } /** @@ -89,14 +93,14 @@ public class HelpTranslationVerifier { Set commandPaths = buildCommandPaths(); Set existingKeys = getLeafKeys("commands"); if (existingKeys.isEmpty()) { - missingCommands.addAll(commandPaths); + missingCommands.addAll(commandPaths); // commandPaths should be empty in this case } else { missingCommands.addAll(Sets.difference(commandPaths, existingKeys)); unknownCommands.addAll(Sets.difference(existingKeys, commandPaths)); } } - private static Set buildCommandPaths() { + private Set buildCommandPaths() { Set commandPaths = new LinkedHashSet<>(); for (CommandDescription command : new CommandInitializer().getCommands()) { commandPaths.addAll(getYamlPaths(command)); @@ -105,11 +109,16 @@ public class HelpTranslationVerifier { return commandPaths; } - private static List getYamlPaths(CommandDescription command) { + private List getYamlPaths(CommandDescription command) { // e.g. commands.authme.register String commandPath = "commands." + CommandUtils.constructParentList(command).stream() .map(cmd -> cmd.getLabels().get(0)) .collect(Collectors.joining(".")); + // The entire command is not present, so just add it as a missing command and don't return any YAML path + if (!configuration.contains(commandPath)) { + missingCommands.add(commandPath); + return Collections.emptyList(); + } // Entries each command can have List paths = newArrayList(commandPath + ".description", commandPath + ".detailedDescription");