Hi, sorry for the late response.
I am not receiving notifications for messages posted to this list for some reason.
(It may be better to create a GitHub ticket instead.)
Question: why are you using ParseResult? Why not just use the annotations?
For example (sorry to use a mixture of Java and Kotlin but you get the idea):
class ShlinkCommand implements Runnable {
@Option(names = "--usr")
String username;
@Option(names = "--pwd")
String password;
public void run() {
// no need to use ParseResult here because picocli populated the annotated fields
if (!username.isNullOrBlank() && !password.isNullOrBlank()) {
oauth2Flow(username, password)
} else {
var context: SecurityContext = SecurityContextHolder.getContext()
val authorities = HashSet<GrantedAuthority>()
authorities.add(SimpleGrantedAuthority("ROLE_Owner"))
context.authentication = AnonymousAuthenticationToken("nekoshlink", "anonymous", authorities)
}
}
public static void main(String[] args) {
IFactory factory = createFactory();
int exitCode = new CommandLine(new ShlinkCommand(), factory).execute(args);
exitProcess(exitCode);
}
}
Alternatively, you don't need to call parseArgs again to get the ParseResult.
Just use execute().
You can get the ParseResult from the CommandLine object, which you can get from the CommandSpec, which you can get using the @Spec annotation:
class ShlinkCommand implements Runnable {
@Option(names = "--usr")
String username;
@Option(names = "--pwd")
String password;
@Spec
CommandSpec spec;
public void run() {
CommandLine.ParseResult parseResult = spec.commandLine().getParseResult();
// ...
}
public static void main(String[] args) {
IFactory factory = createFactory();
int exitCode = new CommandLine(new ShlinkCommand(), factory).execute(args);
exitProcess(exitCode);
}
}