From e8817c9f6e08ab87e48ac6783040f480611883c9 Mon Sep 17 00:00:00 2001 From: AlphaMode Date: Sat, 10 Dec 2022 13:51:03 -0600 Subject: [PATCH] Improve command error messages --- src/main/java/net/fabricmc/stitch/Main.java | 23 +++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/fabricmc/stitch/Main.java b/src/main/java/net/fabricmc/stitch/Main.java index 04eb5a4..331b40a 100644 --- a/src/main/java/net/fabricmc/stitch/Main.java +++ b/src/main/java/net/fabricmc/stitch/Main.java @@ -50,12 +50,23 @@ public static void addCommand(Command command) { } public static void main(String[] args) { - if (args.length == 0 - || !COMMAND_MAP.containsKey(args[0].toLowerCase(Locale.ROOT)) - || !COMMAND_MAP.get(args[0].toLowerCase(Locale.ROOT)).isArgumentCountValid(args.length - 1)) { - if (args.length > 0) { - System.out.println("Invalid command: " + args[0]); - } + boolean commandFailed = false; + if (args.length == 0) { + commandFailed = true; + System.out.println("Invalid command: No arguments supplied!"); + } + + if (!commandFailed && !COMMAND_MAP.containsKey(args[0].toLowerCase(Locale.ROOT))) { + commandFailed = true; + System.out.println("Invalid command: " + args[0]); + } + + if (!commandFailed && !COMMAND_MAP.get(args[0].toLowerCase(Locale.ROOT)).isArgumentCountValid(args.length - 1)) { + commandFailed = true; + System.out.println("Invalid command: Arguments don't match the given command " + args[0]); + } + + if (commandFailed) { System.out.println("Available commands:"); for (Command command : COMMAND_MAP.values()) { System.out.println("\t" + command.name + " " + command.getHelpString());