scanAndBind appears to be failing to find any flags
Test class:
public class FlagTest
{
@FlagInfo(name="debug", altName="d", help="Enable debug logging")
private static final Flag<Boolean> debug = Flagz.valueOf(false);
public static void main(String ... args)
{
Arrays.stream(args).forEach(arg -> System.out.format("ARG FOUND: %s\n", arg));
FlagFieldRegistry registry = Flagz.parse(args);
if(debug.get()) {
System.out.format("Debug logging enabled...\n");
}
}
}
Whether I make the debug field private or public, when attempting to run this snippet I get the following error (against 2.1.0):
ARG FOUND: --debug
Exception in thread "main" org.flagz.FlagException$UnknownFlag: Could not find Flag for name/alt-name 'debug'
at org.flagz.FlagFieldRegistry.parseAll(FlagFieldRegistry.java:56)
at org.flagz.Flagz.parse(Flagz.java:101)
at org.flagz.Flagz.parse(Flagz.java:112)
at org.eoti.sandbox2.flagz.FlagTest.main(FlagTest.java:22)
I have tried with both JDK8 and Jigsaw JDK9.
In parseAll, I can see that
Set<String> unknownNames = Sets.difference(nameToValue.keySet(), allNamesToField.keySet());
nameToValue has my flag, allNamesToField does not.
Checking, I ran with '--help' and saw that my flag was not listed as an option.
It looks like the init function should be adding all nameToValue values into allNamesToField. Maybe I am not calling something I need to?
Ok, I have this resolved but I think it points to a documentation bug.
If I do FlagFieldRegistry registry = Flagz.parse(args, ImmutableList.of("org.eoti.sandbox2.flagz"), ImmutableSet.of(this)); - it works
If I do FlagFieldRegistry registry = Flagz.parse(args); as recommended in the docs, it does not work.
It could be because Flagz.parse(args) will have empty scanners and then scanAndBind will have nothing to iterate over.
@malachid Can you create Pull request with bazel command? I am not able to use flagz actually.
I'm sorry, I don't use this library anymore.