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

Combine positional and flag based arguments #18

Open
xldenis opened this issue Mar 21, 2016 · 6 comments
Open

Combine positional and flag based arguments #18

xldenis opened this issue Mar 21, 2016 · 6 comments

Comments

@xldenis
Copy link

xldenis commented Mar 21, 2016

I'm trying to combine both positional and flag based arguments, I've tried embedding a record in a normal constructor like so:

data Config = Command [String] FlagArguments
data FlagArguments = Args {a :: Bool }

While the parser is correct, the help message is fairly useless:

Usage: proj-exe build [STRING] FlagArguments

What I'd like to get is:

Usage: proj-exe build [STRING] --a

I don't understand haskell generic programming well enough to provide the correct instances though.

@Gabriella439
Copy link
Owner

I think the fix here is to change the instances for tuples from this:

instance (ParseFields a, ParseFields b) => ParseRecord (a, b)

... to this:

instance (ParseRecord a, ParseRecord b) => ParseRecord (a, b)

... and likewise for other tuple instances.

Then the types a and b would be Config and FlagArguments in your case and it would do the right thing.

How does that sound?

@xldenis
Copy link
Author

xldenis commented Mar 27, 2016

Hmm, I don't think that would really solve my issue, I just realized that my example might not have been the best.

A more accurate example could look something like this:

data Config = Build [String] FlagArguments
            | Other [OtherArgs]
data FlagArguments = ...

though I suppose I could restructure it so that Build holds a tuple. 😕

@Gabriella439
Copy link
Owner

Yeah, in general what you want to do is probably not going to work. For example, consider the case where FlagArguments was a labeled field of Build or if it were a sum type

@Gabriella439
Copy link
Owner

For cases like that you will probably have to hand-write the top-level parser to do what you want

@xldenis
Copy link
Author

xldenis commented Mar 28, 2016

Addressing both examples you've given:

  1. If it is a labeled field then we can't generate a meaningful parser since in this case the important distinction is that FlagArguments is itself a record.
  2. Nested sum types pose a different, equally interesting problem: If FlagArguments is a sumtype, then I would expect app build --help to display style of usage message you would get for app --help

Currently, it seems like any nested type gets displayed as TYPENAME in help messages with no further explanation, making it totally useless.

Both nested subcommands and positional + flag based arguments are important for cli tools, I'd be happy to take a stab at implementing these if you feel it's worth supporting.

@Gabriella439
Copy link
Owner

If you think there is a clean way to implement this then I'll be happy to review it

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

2 participants