提问人:Zainab Lawal 提问时间:12/11/2022 最后编辑:marc_sZainab Lawal 更新时间:7/17/2023 访问量:42
如何使用 Picocli 在不指定索引的情况下传递参数
How to Pass params without specifying their index with Picocli
问:
我正在尝试使用 Picocli 创建一个接受可选选项和参数的 cli 程序。我希望参数始终位于传递参数的末尾,但是我不知道如何设置它。 当我尝试以下操作时,这些选项也被解析为文件名。有没有办法解决它?
public class WordCount implements Runnable {
@Parameters(index="*", arity = "1..*", description= "The file to count")
public List<String> filenames;
@Option(names = {"-c", "--countBytes"}, description = "Count the number of Bytes in the file")
private Boolean countBytes= false;
@Option(names= {"-w", "countWords"}, description = "Count the number of Words in the file")
private Boolean countWords = false;
@Option(names = {"-l", "--countLines"}, description = "Count the number of lines in the file")
private Boolean countLines =false;
@Option(names = {"-m", "--countCharacters"}, description = "Count the number of characters in the file")
private Boolean countCharacters =false;
答:
0赞
Zainab Lawal
12/11/2022
#1
我通过在选项中添加 arity 属性来解决这个问题。喜欢:
@Option(names = {"-c", "--countBytes"},arity="1" description = "Count the number of Bytes in the file")
private Boolean countBytes= false;
评论