ndmitchell / cmdargs

Haskell library for command line argument processing
Other
91 stars 12 forks source link

Support nested records #35

Open ndmitchell opened 9 years ago

ndmitchell commented 9 years ago

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 commented 7 years ago

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 👍 😁