Picocli: Parser bug: first argument following clustered options is treated as a positional parameter

Created on 9 Nov 2017  ·  6Comments  ·  Source: remkop/picocli

I use two boolean options. e.g. -c (compress) -e (encrypt) and one string option e.g. -o (outputFile) .
The i use parameter "1..*" FILE for inputFileNames(String[]).

Usage:
cmd -c -e -o OUTPUTFILE INPUTFILE1 INPUTFILE2 INPUTFILE3 -> work
cmd -ceo OUTPUTFILE INPUTFILE1 INPUTFILE2 INPUTFILE3 -> work
cmd -ce -o OUTPUTFILE INPUTFILE1 INPUTFILE2 INPUTFILE -> failed
will be parsed to:
outputFIle=null
inputFileNames[0]="-o"
inputFileNames[1]="OUTPUTFILE"
inputFileNames[2]="INPUTFILE1"
...
cmd -ce -o=OUTPUTFILE INPUTFILE1 INPUTFILE2 INPUTFILE -> failed
will be parsed to:
outputFIle=null
inputFileNames[0]="-o=OUTPUTFILE"
inputFileNames[1]="INPUTFILE1"
...

bug

All 6 comments

I will look at this when I get to a PC. Does this match your class? Please let me know if you use different field types or annotation attributes (other than description).

class Mix {
  @Option(names = “-e”, description = “Encrypt”)
  boolean encrypt;

  @Option(names = “-c”, description = “Compress”)
  boolean compress;

  @Option(names = “-o”, description = “Output file”)
  String outputFile;

  @Parameters(arity = “1..*”, description = “One or more input files”)
  String[] inputFiles;
}

I was able to reproduce the issue. Thanks for reporting this!

I will try to release picocli 2.0.3 with the fix this weekend.

Picocli 2.0.3 has been released with this fix.

Thanks again for the bug report! Keep ‘em coming!

Thanks for your amazing work on this project!

Was this page helpful?
0 / 5 - 0 ratings