Can't parse `some` or `many` arguments followed by one
I want to implement cp-like behavior, where many arguments are parsed as source and then the last one as destination. But this fails with optparse-applicative. The only way which works is to swap the order: have one argument followed by many args.
So, this works:
ghci> execParserMaybe (info ((,) <$> (strArgument mempty) <*> many (strArgument mempty)) mempty) $ ["a", "b", "c"]
Just ("a",["b","c"])
But this doesn't:
ghci> execParserMaybe (info ((,) <$> many (strArgument mempty) <*> strArgument mempty) mempty) $ ["a", "b", "c"]
Nothing
I don't have a great answer for this. It's like in Text.Parsec or Data.Attoparsec saying:
let a = (,) <$> many anyChar <*> anyChar
You'll never reach the last char as the many is too greedy. It's possible to do this with a lookahead in Parsec, but that's something rather heavy for a command line parser.
(remember too that you can always take the init and last from the parsed args list)
@w3rs I would suggest using a single many argument and then simply take the last item from the resulting list and strip off the last item of the list and give it whatever different treatment you need.
Has there been any progress on this issue? This is a feature I would like to have.