From dcee5ae80f30dcc8246aabae16dd0962f4af4287 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Wed, 10 May 2023 13:54:52 +0100 Subject: [PATCH] JAL-629 Check Arg options for obtaining boolean or negative boolean arg from subvals --- src/jalview/bin/argparser/ArgParser.java | 51 ++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 7 deletions(-) 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; } -- 1.7.10.2