From: Ben Soares Date: Wed, 10 May 2023 12:54:52 +0000 (+0100) Subject: JAL-629 Check Arg options for obtaining boolean or negative boolean arg from subvals X-Git-Tag: Release_2_11_4_0~338 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=dcee5ae80f30dcc8246aabae16dd0962f4af4287;p=jalview.git JAL-629 Check Arg options for obtaining boolean or negative boolean arg from subvals --- diff --git a/src/jalview/bin/argparser/ArgParser.java b/src/jalview/bin/argparser/ArgParser.java index d551b26..c7fb323 100644 --- a/src/jalview/bin/argparser/ArgParser.java +++ b/src/jalview/bin/argparser/ArgParser.java @@ -844,22 +844,59 @@ public class ArgParser public static boolean getFromSubValArgOrPref(ArgValuesMap avm, Arg a, SubVals sv, String key, String pref, boolean def) { + if ((key == null && a == null) || (sv == null && a == null)) + return false; + + boolean usingArgKey = false; if (key == null) + { key = a.getName(); + usingArgKey = true; + } + String nokey = ArgParser.NEGATESTRING + key; - if (sv != null && sv.has(key) && sv.get(key) != null) - return sv.get(key).toLowerCase(Locale.ROOT).equals("true"); - if (sv != null && sv.has(key) && sv.get(key) != null) - return sv.get(key).toLowerCase(Locale.ROOT).equals("true"); + // look for key or nokey in subvals first (if using Arg check options) + if (sv != null) + { + // check for true boolean + if (sv.has(key) && sv.get(key) != null) + { + if (usingArgKey) + { + if (!(a.hasOption(Opt.BOOLEAN) || a.hasOption(Opt.UNARY))) + { + Console.debug( + "Looking for boolean in subval from non-boolean/non-unary Arg " + + a.getName()); + return false; + } + } + return sv.get(key).toLowerCase(Locale.ROOT).equals("true"); + } - // check for negative boolean (subval "no..." will be "true") - if (sv != null && sv.has(nokey) && sv.get(nokey) != null) - return !sv.get(nokey).toLowerCase(Locale.ROOT).equals("true"); + // check for negative boolean (subval "no..." will be "true") + if (sv.has(nokey) && sv.get(nokey) != null) + { + if (usingArgKey) + { + if (!(a.hasOption(Opt.BOOLEAN))) + { + Console.debug( + "Looking for negative boolean in subval from non-boolean Arg " + + a.getName()); + return false; + } + } + return !sv.get(nokey).toLowerCase(Locale.ROOT).equals("true"); + } + } + // check argvalues if (avm != null && avm.containsArg(a)) return avm.getBoolean(a); + // return preference or default return pref != null ? Cache.getDefault(pref, def) : def; }