Skip to content

Commit 7f47625

Browse files
committed
correct error parsing arguments
1 parent d631ca2 commit 7f47625

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

src/main/java/ai/nets/samj/ij/SAMJ_Annotator.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class SAMJ_Annotator implements PlugIn {
8181
/**
8282
* Optional keys to run SAMJ run with a macro or in headless mode
8383
*/
84-
private final static String[] macroOptionalKeys = new String[] {"model=", "maskPrompt=", "export="};
84+
private final static String[] macroOptionalKeys = new String[] {"model", "maskPrompt", "export"};
8585

8686
private static Consumer MACRO_CONSUMER;
8787

@@ -435,23 +435,12 @@ private void parseCommand() {
435435
}
436436

437437
private static String parseArg(String macroArg, String arg, boolean required) {
438-
int modelFolderInd = macroArg.indexOf(arg);
439-
if (modelFolderInd == -1 && required)
438+
String value = Macro.getValue(macroArg, arg, null);
439+
if (value != null && value.equals(""))
440+
value = null;
441+
if (value == null && required)
440442
throw new IllegalArgumentException("SAMJ macro requires to the variable '" + arg + "'. "
441443
+ "For more info, please visit: " + MACRO_INFO);
442-
else if (modelFolderInd == -1)
443-
return null;
444-
int modelFolderInd2 = macroArg.indexOf(arg + "=[");
445-
int endInd = macroArg.indexOf(" ", modelFolderInd);
446-
String value;
447-
if (modelFolderInd2 != -1) {
448-
endInd = macroArg.indexOf("] ", modelFolderInd2);
449-
value = macroArg.substring(modelFolderInd2 + arg.length() + 1, endInd);
450-
} else {
451-
value = macroArg.substring(modelFolderInd + arg.length(), endInd);
452-
}
453-
if (value.equals("null") || value.equals(""))
454-
value = null;
455444
return value;
456445
}
457446
}

0 commit comments

Comments
 (0)