Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't parse some or many arguments followed by one #163

Open
richsmith92 opened this issue Nov 4, 2015 · 3 comments
Open

Can't parse some or many arguments followed by one #163

richsmith92 opened this issue Nov 4, 2015 · 3 comments

Comments

@richsmith92
Copy link

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
@HuwCampbell
Copy link
Collaborator

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)

@mightybyte
Copy link

@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.

@justinlovinger
Copy link

Has there been any progress on this issue? This is a feature I would like to have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants