1

I want to implement the following logic of Option default value calculation

@Command(name = "test-command")
public class TestCommand implements Callable {
    
    @Autowired
    DefaultValueUtils utils;
    
    @ArgGroup
    EntityGroup functions = new EntityGroup();
    
    class EntityGroup {
        @Option(names = "--function1", defaultValue = "true")
        boolean function1 = utils.isFunction1();

        @Option(names = "--function2", defaultValue = "true")
        boolean function2 = utils.isFunction2();
    }
    
    ...
}

I have 2 boolean options - function1 and function2; if they are not provided their default values are specified in some other place. But if options provided, I need to override values with provided ones. One more problem is in following logic:

if none of them provided - default values should be calculated; If one of them provided - only provided one is true, not provided false; If both provided - both are true

How can I implement this?

This current block of the code is failing because utils is null during EntityGroup instantiation.

olly2334
  • 11
  • 2
  • How do you setup your application? Did you use pico cli springboot integration https://github.com/remkop/picocli/blob/main/picocli-spring-boot-starter/README.md – samabcde Dec 23 '22 at 11:40
  • Yes, of course I use. I debugged and it seems like options default values initialization happen before injection of @Autowired fields. So at that point of time I got NPE – olly2334 Dec 23 '22 at 16:40

0 Answers0