ndmitchell / cmdargs

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

Using the `explicit` annotation (with `System.Console.CmdArgs.Implicit`) isn't honored #37

Open noteed opened 9 years ago

noteed commented 9 years ago

I simply switched compiler versions from GHC 7.6.3 to GHC 7.8.4, using the same cmdargs version, 0.10.13 and suddenly invoking --help on a subcommand reported a flag named --cmddatabaseurl instead of --database-url. The record field is cmdDatabaseUrl :: String.

I will try to come up with a minimal example soon.

ndmitchell commented 9 years ago

Can you please try setting {-# OPTIONS_GHC -fno-cse #-} at the top of the file - does that fix it?

noteed commented 9 years ago

Yes it does. I guess I'll use it until I convert everything to the Explicit variant.

Thanks for the quick reply and the workaround. I now think I've seen the suggestion elsewhere, maybe by you on reddit or twitter or in the doc. Thanks!

gridaphobe commented 8 years ago

It's worth noting that -fno-cse doesn't help if the "config" type has strict fields, in which case the annotations are ignored again. For example, using the README's first example

{-# LANGUAGE DeriveDataTypeable #-}
{-# OPTIONS_GHC -fno-cse #-}

import System.Console.CmdArgs.Implicit

data Sample = Sample {hello :: !String} deriving (Show, Data, Typeable)

sample = Sample {
    hello = def &= help "World argument" &= opt "world"
  } &= summary "Sample v1"

main = print =<< cmdArgs sample
$ runghc Main.hs --help
Main.hs: System.Console.CmdArgs.Implicit, unexpected mode: FlagOptional "world"