Placing option values into an object or collection #2324
-
I'm very new to picocli, and like what I see, but I'm curious about how people manage multiple command line options. @Option(names = {"-f", "--file"}, required = true, description = "Name of the to be processed")
private String fileName;
@Option(names = {"-p", "--pattern"}, required = true, description = "regex pattern to process")
private String pattern;
@Option(names = {"-a", "--algorithm"}, required = true, description = "crypto algorithm used for encryption")
private String cryptoAlgorithm;
@Option(names = {"-l", "--flag"}, description = "some sort of boolean flag")
private Boolean theFlag; now, I have four member variables to worry about. I was wondering if there was a way to automatically instantiate, or stuff them into an object/record or collection, so that they can be passed around easily. I'm doing this by hand right now, and that works, but is there a way to do this automatically? I'm guessing that this would be especially annoying if I was building something like curl, with a kazillion options. Maybe something like this... @Option(names = {"-f", "--file"}, required = true, key="file", description = "Name of the to be processed")
@Option(names = {"-p", "--pattern"}, required = true, key="regexPattern", description = "regex pattern to process")
@Option(names = {"-a", "--algorithm"}, required = true, key="algorithm" description = "crypto algorithm used for encryption")
@Option(names = {"-l", "--flag"}, description = "some sort of boolean flag", key="flag")
private HashMap<String, Object> options; then I access any value like: Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
In my own applications, when I need an object that has (some of the) options without the rest of the logic of that command, I put those options in a separate class. Then in my command I include those options with the |
Beta Was this translation helpful? Give feedback.
https://picocli.info/#_mixins