pacak / bpaf

Command line parser with applicative interface
Apache License 2.0
340 stars 17 forks source link

adjacent is not working if first argument requires more than one item to succeed #292

Open pacak opened 1 year ago

pacak commented 1 year ago
let x = short('x').argument::<f32>("X");
let y = short('y').argument::<f32>("Y");
let p = short('p').req_flag(());
construct!(p, x, y)

Without p this fails since adjacent detects left most item with magic...

polarathene commented 9 months ago
  • document that adjacent block must start with a flag?

Is this related to the bugs experienced with a subcommand with overlapping flags (short names)?: https://github.com/pacak/bpaf/issues/325

pacak commented 9 months ago

Is this related to the bugs experienced with a subcommand with overlapping flags (short names)?:

I don't think so. Current logic to restrict scope to adjacent values is something like this:

  1. run the parser showing it each unconsumed item individually, parser will fail, but it might start consuming items. Set this position as a starting point for the region
  2. run the parser again, showing it items from the start of the region until the end of the span of adjacent unconsumed items
  3. if consumed blocks are all adjacent to each other - that's the result, if not - narrow the span to adjacent block and goto 2.

This works if first item in the parser wants to consume let's say -p, but it doesn't work if it wants let's say -x 3 - -x part will be available, 3 - won't be and argument parser checks that both name and value are present. It works this way because some unrelated reasons.