Skip to content

Commit

Permalink
limitToOnlyPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 13, 2021
1 parent 473f529 commit 813a026
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 17 deletions.
Expand Up @@ -217,6 +217,13 @@ public boolean matchesEnumList(Enum<?>[] values) {
return false;
}

public boolean limitToOnlyPrefix(String value) {
if (!hasPrefix()) {
return true;
}
return value.equals(lower_prefix);
}

public boolean matchesPrefix(String value) {
if (!hasPrefix()) {
return false;
Expand Down
Expand Up @@ -78,7 +78,8 @@ public void addCustomTabCompletions(String arg, Consumer<String> addOne) {
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry.getProcessedArgs()) {
if (!scriptEntry.hasObject("object")) {
if (!scriptEntry.hasObject("object")
&& arg.limitToOnlyPrefix("object")) {
if (arg.object instanceof ListTag) {
scriptEntry.addObject("object", arg.object);
}
Expand Down
Expand Up @@ -86,6 +86,7 @@ public enum DebugType {
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry.getProcessedArgs()) {
if (!scriptEntry.hasObject("type")
&& arg.limitToOnlyPrefix("type")
&& arg.matchesEnum(DBINFO)) {
scriptEntry.addObject("type", arg.asElement());
}
Expand Down
Expand Up @@ -85,12 +85,12 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
boolean handled = false;
for (Argument arg : scriptEntry.getProcessedArgs()) {
if (!handled
&& arg.matches("stop")) {
&& arg.matches("stop") && !arg.hasPrefix()) {
scriptEntry.addObject("stop", new ElementTag(true));
handled = true;
}
else if (!handled
&& arg.matches("next")) {
&& arg.matches("next") && !arg.hasPrefix()) {
scriptEntry.addObject("next", new ElementTag(true));
handled = true;
}
Expand Down
Expand Up @@ -66,10 +66,11 @@ else if (arg.matches("local", "locally")) {
}
else if (!scriptEntry.hasObject("script")
&& arg.matchesArgumentType(ScriptTag.class)
&& !arg.matchesPrefix("p", "path")) {
&& arg.limitToOnlyPrefix("script")) {
scriptEntry.addObject("script", arg.asType(ScriptTag.class));
}
else if (!scriptEntry.hasObject("path")) {
else if (!scriptEntry.hasObject("path")
&& arg.matchesPrefix("path", "p")) {
String path = arg.asElement().asString();
if (!scriptEntry.hasObject("script")) {
int dotIndex = path.indexOf('.');
Expand Down
Expand Up @@ -54,10 +54,12 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException

for (Argument arg : scriptEntry.getProcessedArgs()) {
if (arg.matchesArgumentType(DurationTag.class)
&& !scriptEntry.hasObject("duration")) {
&& !scriptEntry.hasObject("duration")
&& arg.limitToOnlyPrefix("duration")) {
scriptEntry.addObject("duration", arg.asType(DurationTag.class));
}
else if (!scriptEntry.hasObject("object")) {
else if (!scriptEntry.hasObject("object")
&& arg.limitToOnlyPrefix("object")) {
scriptEntry.addObject("object", new ElementTag(arg.getRawValue()));
}
else {
Expand Down
Expand Up @@ -64,22 +64,22 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
boolean handled = false;
for (Argument arg : scriptEntry.getProcessedArgs()) {
if (!handled
&& arg.matchesInteger()) {
&& arg.matchesInteger() && !arg.hasPrefix()) {
scriptEntry.addObject("quantity", arg.asElement());
handled = true;
}
else if (!handled
&& arg.matches("stop")) {
&& arg.matches("stop") && !arg.hasPrefix()) {
scriptEntry.addObject("stop", new ElementTag(true));
handled = true;
}
else if (!handled
&& arg.matches("next")) {
&& arg.matches("next") && !arg.hasPrefix()) {
scriptEntry.addObject("next", new ElementTag(true));
handled = true;
}
else if (!handled
&& arg.matches("\0callback")) {
&& arg.matches("\0callback") && !arg.hasPrefix()) {
scriptEntry.addObject("callback", new ElementTag(true));
handled = true;
}
Expand Down
Expand Up @@ -139,14 +139,15 @@ else if (arg.hasPrefix()
}
else if (!scriptEntry.hasObject("script")
&& arg.matchesArgumentType(ScriptTag.class)
&& !arg.matchesPrefix("p", "path")) {
&& arg.limitToOnlyPrefix("script")) {
scriptEntry.addObject("script", arg.asType(ScriptTag.class));
}
else if (!arg.hasPrefix() && arg.getRawValue().startsWith("def.") && arg.getRawValue().contains(":")) {
int colon = arg.getRawValue().indexOf(':');
defMap.putObject(arg.getRawValue().substring("def.".length(), colon), new ElementTag(arg.getRawValue().substring(colon + 1)));
}
else if (!scriptEntry.hasObject("path")) {
else if (!scriptEntry.hasObject("path")
&& arg.matchesPrefix("path", "p")) {
String path = arg.asElement().asString();
if (!scriptEntry.hasObject("script")) {
int dotIndex = path.indexOf('.');
Expand Down
Expand Up @@ -90,10 +90,11 @@ else if (arg.hasPrefix()
}
else if (!scriptEntry.hasObject("script")
&& arg.matchesArgumentType(ScriptTag.class)
&& !arg.matchesPrefix("path")) {
&& arg.limitToOnlyPrefix("script")) {
scriptEntry.addObject("script", arg.asType(ScriptTag.class));
}
else if (!scriptEntry.hasObject("path")) {
else if (!scriptEntry.hasObject("path")
&& arg.matchesPrefix("path", "p")) {
String path = arg.asElement().asString();
if (!scriptEntry.hasObject("script")) {
int dotIndex = path.indexOf('.');
Expand Down
Expand Up @@ -51,11 +51,13 @@ public WaitCommand() {
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry.getProcessedArgs()) {
if (arg.matchesArgumentType(DurationTag.class)
&& !scriptEntry.hasObject("delay")) {
&& !scriptEntry.hasObject("delay")
&& arg.limitToOnlyPrefix("delay")) {
scriptEntry.addObject("delay", arg.asType(DurationTag.class));
}
else if (arg.matchesArgumentType(QueueTag.class)
&& !scriptEntry.hasObject("queue")) {
&& !scriptEntry.hasObject("queue")
&& arg.limitToOnlyPrefix("queue")) {
scriptEntry.addObject("delay", arg.asType(QueueTag.class));
}
else if (arg.matches("system")
Expand Down

0 comments on commit 813a026

Please sign in to comment.