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

Support nested records #35

Open
ndmitchell opened this issue Aug 17, 2015 · 1 comment
Open

Support nested records #35

ndmitchell opened this issue Aug 17, 2015 · 1 comment

Comments

@ndmitchell
Copy link
Owner

From http://code.google.com/p/ndmitchell/issues/detail?id=291:

@aavogt says: cmdargs should support nested records:

> data A = A { optA :: X, optB :: Y }
> data Y = Y { xopt :: X, optionY :: Bool }
> data X = X { path :: String, optionX :: Bool }

It should be possible to use:

> mode (A (X "here" True) (Y (X "there" False) True)

Which would infer flags including:

 --opta-optionx, --optb-xopt-path

It would be nice not to have to expand the redundancy in the arguments in
the usage description, but I'm not sure when or how that should be done.

@ndmitchell replied:It's possible it should just infer --optionx and --path, so the nesting is for the
author of CmdArgs, not the user. Anyway, something should be done.

@mdibaiee
Copy link

mdibaiee commented Mar 5, 2017

Hey Neil!

First of all, thanks for CmdArgs, awesome work!

I just encountered this problem, my different modes have overlapping record key names, and in order to make the code a little cleaner and avoid fName, dName, I separated my modes to different files so I could have F.name and D.name. But then I realized I won't be able to create a Sum Type over those without wrapping them in another constructor.
This is what it looks like right now:

-- Main.hs
data Params = WebServerParams W.Params
            | FileSharingParams F.Params
            deriving (Show, Typeable, Data)
-- WebServer.hs
data Params = Params { name :: String } deriving (Show, Typeable, Data)

But then, this does not quite work as CmdArgs looks only one level deep for properties.

Do you have any ideas how I could workaround this problem?

If you think I could fix this issue, please direct me to the related files and I will look into it.

Thanks in advance 👍 😁

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