Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Improve command error messages #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/main/java/net/fabricmc/stitch/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down