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

Parse at least one argument #20

Closed
lambda-fairy opened this issue Sep 20, 2012 · 7 comments
Closed

Parse at least one argument #20

lambda-fairy opened this issue Sep 20, 2012 · 7 comments

Comments

@lambda-fairy
Copy link

I'm writing a program that takes multiple arguments and performs an operation on each. Unfortunately, the arguments parser succeeds even when I supply no arguments, even though it doesn't make sense for my application.

Is there a way to force arguments to parse at least one argument?

@dag
Copy link
Contributor

dag commented Sep 20, 2012

You want something like, some argument. Have a look at Alternative which the parser is an instance of.

@lambda-fairy
Copy link
Author

Thanks – I've tried using some (argument ...) and (:) <$> argument ... <*> arguments ... and they both share the same problem. When I invoke the program with the --help option, the argument parser gobbles it up, and then my program tries to process it rather than displaying help as it should.

@dag
Copy link
Contributor

dag commented Sep 21, 2012

Ah yea, that issue was fixed in arguments but not argument. I would like the former to be simply something like many argument but perhaps that's non-trivial or not possible for some reason? In the mean time you should be able to work around it by having the reader return Nothing if the argument starts with a hyphen.

@lambda-fairy
Copy link
Author

That works – thank you again.

The inconsistent behavior should probably go in a separate issue, so I'm closing this for now.

@pcapriotti
Copy link
Owner

The problem here is that arguments has some special logic to:

  • initially ignore arguments starting with '-'
  • accept '--'
  • accept arguments starting with '-' after '--' is encountered

Given this desired behavior, arguments cannot simply be implemented as many argument.

What we can do to make common use cases like the one in this Issue easier to
deal with, is to add a bunch of convenience builders, like:

  • arguments1, non-empty argument list, with the same behavior as arguments
  • argument', parse 1 argument, ignoring things starting with '-'

This way, many argument' would be similar to arguments (without the special
handling of --), and some argument' to arguments1.

Suggestions for better names are welcome. :)

@pcapriotti pcapriotti reopened this Sep 23, 2012
@pcapriotti
Copy link
Owner

Fixed by 700e07b,

@dag
Copy link
Contributor

dag commented Sep 28, 2012

I'm sort of pondering if this should happen at a lower level, splitting the input before parsing?

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

3 participants