• mnislaih's avatar
    #223 part 1: Extend Distribution.Command.Simple.Option · 7bbbe596
    mnislaih authored
         so that it really represents an option and not just a flag.
         It's been renamed to OptionField as it models a field in a flags-like data structure. 
            data OptionField a = OptionField {
              optionName        :: Name,
              optionDescr       :: [OptDescr a] }
            data OptDescr a  = ReqArg Description OptFlags ArgDescr (ReadE (a->a))         (a -> [String])
                             | OptArg Description OptFlags ArgDescr (ReadE (a->a)) (a->a)  (a -> [Maybe String])
                             | ChoiceOpt [(Description, OptFlags, a->a, a -> Bool)]
    			 | BoolOpt Description OptFlags{-True-} OptFlags{-False-} (Bool -> a -> a) (a -> Bool)
          An option field can expand to several command line options, which are all defined together.
          For example, the compiler flag is defined as follows.
                option [] ["compiler"] "compiler"
                   configHcFlavor (\v flags -> flags { configHcFlavor = v })
                   (choiceOpt [ (Flag GHC, ("g", ["ghc"]), "compile with GHC")
                              , (Flag NHC, ([] , ["nhc98"]), "compile with NHC")
                              , (Flag JHC, ([] , ["jhc"]), "compile with JHC")
                              , (Flag Hugs,([] , ["hugs"]), "compile with Hugs")])
          We can need to use several kinds of OptDescr for the same option, as in the 
          optimization Option (really a extreme case):
                ,multiOption "optimization"
                   configOptimization (\v flags -> flags { configOptimization = v })
                   [optArg' "n" (Flag . flagToOptimisationLevel)
                            "Build with optimization (n is 0--2, default is 1)",
                    noArg (Flag NoOptimisation) []