ndmitchell / cmdargs

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

Way to use multiple modes without partial record field selectors? #61

Closed vaclavsvejcar closed 3 years ago

vaclavsvejcar commented 4 years ago

According to README, when I want to use multiple modes, I need to define data record with more constructors, like this

data CmdOptions =
    Foo { foo :: String }
  | Bar { bar :: String }
  deriving (Eq, Data, Show, Typeable)

which unfortunately leads to issue with partial record field selectors and GHC complains about this:

warning: [-Wpartial-fields]
    Use of partial record field selector: ‘foo’

I was wondering if there's another way how to define data types for multiple modes to avoid this?

One more minor question - is there any way to define only one mode and make it mandatory? Use case for this - right now I'd like to call my app with myApp mode, not just myApp, because I plan more modes in future and want to keep things consistent.

Thanks a lot in advance :)

tesujimath commented 3 years ago

FYI a reasonable work-around is to do the argument handling by itself in its own tiny source file, where this warning is disabled using:

{-# OPTIONS_GHC -Wno-partial-fields #-}

while for everywhere else in my project, my Cabal file defines -Wpartial-fields giving me this check where I want it.

Hope this helps.

vaclavsvejcar commented 3 years ago

@tesujimath Thanks for this recommendation. In the meantime as I progressed with Haskell, I ended up using optparse-applicative, so I guess this issue is no longer relevant and I can close it.