Skip to content

Commit

Permalink
Fix flag parsing to allow non-counting left over args before flags
Browse files Browse the repository at this point in the history
  • Loading branch information
masonsbro committed Jun 12, 2013
1 parent db6856b commit 9d91542
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/main/java/com/sk89q/mclauncher/util/BasicArgsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,12 @@ public ArgsContext parse(String[] args) {
List<String> leftOver = new ArrayList<String>();
Set<String> flags = new HashSet<String>();
Map<String, String> values = new HashMap<String, String>();

boolean processingFlags = true;

String wantingFlag = null;

for (int i = 0; i < args.length; i++) {
String arg = args[i];
if (arg.startsWith("-")) {
if (!processingFlags) {
throw new IllegalArgumentException("Flags must come first");
}
if (arg.length() == 1) {
throw new IllegalArgumentException("Flag with no name");
}
String flag = arg.substring(1);
if (valueArgs.contains(flag)) {
wantingFlag = flag;
Expand All @@ -67,7 +60,6 @@ public ArgsContext parse(String[] args) {
values.put(wantingFlag, arg);
wantingFlag = null;
} else {
processingFlags = false;
leftOver.add(arg);
}
}
Expand Down

0 comments on commit 9d91542

Please sign in to comment.