cmdargs icon indicating copy to clipboard operation
cmdargs copied to clipboard

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

Open noteed opened this issue 9 years ago • 3 comments
trafficstars

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.

noteed avatar Nov 25 '15 19:11 noteed

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

ndmitchell avatar Nov 25 '15 22:11 ndmitchell

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!

noteed avatar Nov 25 '15 22:11 noteed

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"

gridaphobe avatar Jan 18 '16 21:01 gridaphobe