{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}

-----------------------------------------------------------------------------

-- |
-- Module      :  Distribution.Simple.Setup.Hscolour
-- Copyright   :  Isaac Jones 2003-2004
--                Duncan Coutts 2007
-- License     :  BSD3
--
-- Maintainer  :  cabal-devel@haskell.org
-- Portability :  portable
--
-- Definition of the hscolour command-line options.
-- See: @Distribution.Simple.Setup@
module Distribution.Simple.Setup.Hscolour
  ( HscolourFlags (..)
  , emptyHscolourFlags
  , defaultHscolourFlags
  , hscolourCommand
  ) where

import Distribution.Compat.Prelude hiding (get)
import Prelude ()

import Distribution.Simple.Command hiding (boolOpt, boolOpt')
import Distribution.Simple.Flag
import Distribution.Verbosity

import Distribution.Simple.Setup.Common

-- ------------------------------------------------------------

-- * HsColour flags

-- ------------------------------------------------------------

data HscolourFlags = HscolourFlags
  { HscolourFlags -> Flag FilePath
hscolourCSS :: Flag FilePath
  , HscolourFlags -> Flag Bool
hscolourExecutables :: Flag Bool
  , HscolourFlags -> Flag Bool
hscolourTestSuites :: Flag Bool
  , HscolourFlags -> Flag Bool
hscolourBenchmarks :: Flag Bool
  , HscolourFlags -> Flag Bool
hscolourForeignLibs :: Flag Bool
  , HscolourFlags -> Flag FilePath
hscolourDistPref :: Flag FilePath
  , HscolourFlags -> Flag Verbosity
hscolourVerbosity :: Flag Verbosity
  , HscolourFlags -> Flag FilePath
hscolourCabalFilePath :: Flag FilePath
  }
  deriving (Int -> HscolourFlags -> ShowS
[HscolourFlags] -> ShowS
HscolourFlags -> FilePath
(Int -> HscolourFlags -> ShowS)
-> (HscolourFlags -> FilePath)
-> ([HscolourFlags] -> ShowS)
-> Show HscolourFlags
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HscolourFlags -> ShowS
showsPrec :: Int -> HscolourFlags -> ShowS
$cshow :: HscolourFlags -> FilePath
show :: HscolourFlags -> FilePath
$cshowList :: [HscolourFlags] -> ShowS
showList :: [HscolourFlags] -> ShowS
Show, (forall x. HscolourFlags -> Rep HscolourFlags x)
-> (forall x. Rep HscolourFlags x -> HscolourFlags)
-> Generic HscolourFlags
forall x. Rep HscolourFlags x -> HscolourFlags
forall x. HscolourFlags -> Rep HscolourFlags x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HscolourFlags -> Rep HscolourFlags x
from :: forall x. HscolourFlags -> Rep HscolourFlags x
$cto :: forall x. Rep HscolourFlags x -> HscolourFlags
to :: forall x. Rep HscolourFlags x -> HscolourFlags
Generic, Typeable)

emptyHscolourFlags :: HscolourFlags
emptyHscolourFlags :: HscolourFlags
emptyHscolourFlags = HscolourFlags
forall a. Monoid a => a
mempty

defaultHscolourFlags :: HscolourFlags
defaultHscolourFlags :: HscolourFlags
defaultHscolourFlags =
  HscolourFlags
    { hscolourCSS :: Flag FilePath
hscolourCSS = Flag FilePath
forall a. Flag a
NoFlag
    , hscolourExecutables :: Flag Bool
hscolourExecutables = Bool -> Flag Bool
forall a. a -> Flag a
Flag Bool
False
    , hscolourTestSuites :: Flag Bool
hscolourTestSuites = Bool -> Flag Bool
forall a. a -> Flag a
Flag Bool
False
    , hscolourBenchmarks :: Flag Bool
hscolourBenchmarks = Bool -> Flag Bool
forall a. a -> Flag a
Flag Bool
False
    , hscolourDistPref :: Flag FilePath
hscolourDistPref = Flag FilePath
forall a. Flag a
NoFlag
    , hscolourForeignLibs :: Flag Bool
hscolourForeignLibs = Bool -> Flag Bool
forall a. a -> Flag a
Flag Bool
False
    , hscolourVerbosity :: Flag Verbosity
hscolourVerbosity = Verbosity -> Flag Verbosity
forall a. a -> Flag a
Flag Verbosity
normal
    , hscolourCabalFilePath :: Flag FilePath
hscolourCabalFilePath = Flag FilePath
forall a. Monoid a => a
mempty
    }

instance Monoid HscolourFlags where
  mempty :: HscolourFlags
mempty = HscolourFlags
forall a. (Generic a, GMonoid (Rep a)) => a
gmempty
  mappend :: HscolourFlags -> HscolourFlags -> HscolourFlags
mappend = HscolourFlags -> HscolourFlags -> HscolourFlags
forall a. Semigroup a => a -> a -> a
(<>)

instance Semigroup HscolourFlags where
  <> :: HscolourFlags -> HscolourFlags -> HscolourFlags
(<>) = HscolourFlags -> HscolourFlags -> HscolourFlags
forall a. (Generic a, GSemigroup (Rep a)) => a -> a -> a
gmappend

hscolourCommand :: CommandUI HscolourFlags
hscolourCommand :: CommandUI HscolourFlags
hscolourCommand =
  CommandUI
    { commandName :: FilePath
commandName = FilePath
"hscolour"
    , commandSynopsis :: FilePath
commandSynopsis =
        FilePath
"Generate HsColour colourised code, in HTML format."
    , commandDescription :: Maybe ShowS
commandDescription = ShowS -> Maybe ShowS
forall a. a -> Maybe a
Just (\FilePath
_ -> FilePath
"Requires the hscolour program.\n")
    , commandNotes :: Maybe ShowS
commandNotes = ShowS -> Maybe ShowS
forall a. a -> Maybe a
Just (ShowS -> Maybe ShowS) -> ShowS -> Maybe ShowS
forall a b. (a -> b) -> a -> b
$ \FilePath
_ ->
        FilePath
"Deprecated in favour of 'cabal haddock --hyperlink-source'."
    , commandUsage :: ShowS
commandUsage = \FilePath
pname ->
        FilePath
"Usage: " FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
pname FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
" hscolour [FLAGS]\n"
    , commandDefaultFlags :: HscolourFlags
commandDefaultFlags = HscolourFlags
defaultHscolourFlags
    , commandOptions :: ShowOrParseArgs -> [OptionField HscolourFlags]
commandOptions = \ShowOrParseArgs
showOrParseArgs ->
        [ (HscolourFlags -> Flag Verbosity)
-> (Flag Verbosity -> HscolourFlags -> HscolourFlags)
-> OptionField HscolourFlags
forall flags.
(flags -> Flag Verbosity)
-> (Flag Verbosity -> flags -> flags) -> OptionField flags
optionVerbosity
            HscolourFlags -> Flag Verbosity
hscolourVerbosity
            (\Flag Verbosity
v HscolourFlags
flags -> HscolourFlags
flags{hscolourVerbosity = v})
        , (HscolourFlags -> Flag FilePath)
-> (Flag FilePath -> HscolourFlags -> HscolourFlags)
-> ShowOrParseArgs
-> OptionField HscolourFlags
forall flags.
(flags -> Flag FilePath)
-> (Flag FilePath -> flags -> flags)
-> ShowOrParseArgs
-> OptionField flags
optionDistPref
            HscolourFlags -> Flag FilePath
hscolourDistPref
            (\Flag FilePath
d HscolourFlags
flags -> HscolourFlags
flags{hscolourDistPref = d})
            ShowOrParseArgs
showOrParseArgs
        , FilePath
-> LFlags
-> FilePath
-> (HscolourFlags -> Flag Bool)
-> (Flag Bool -> HscolourFlags -> HscolourFlags)
-> MkOptDescr
     (HscolourFlags -> Flag Bool)
     (Flag Bool -> HscolourFlags -> HscolourFlags)
     HscolourFlags
-> OptionField HscolourFlags
forall get set a.
FilePath
-> LFlags
-> FilePath
-> get
-> set
-> MkOptDescr get set a
-> OptionField a
option
            FilePath
""
            [FilePath
"executables"]
            FilePath
"Run hscolour for Executables targets"
            HscolourFlags -> Flag Bool
hscolourExecutables
            (\Flag Bool
v HscolourFlags
flags -> HscolourFlags
flags{hscolourExecutables = v})
            MkOptDescr
  (HscolourFlags -> Flag Bool)
  (Flag Bool -> HscolourFlags -> HscolourFlags)
  HscolourFlags
forall a. MkOptDescr (a -> Flag Bool) (Flag Bool -> a -> a) a
trueArg
        , FilePath
-> LFlags
-> FilePath
-> (HscolourFlags -> Flag Bool)
-> (Flag Bool -> HscolourFlags -> HscolourFlags)
-> MkOptDescr
     (HscolourFlags -> Flag Bool)
     (Flag Bool -> HscolourFlags -> HscolourFlags)
     HscolourFlags
-> OptionField HscolourFlags
forall get set a.
FilePath
-> LFlags
-> FilePath
-> get
-> set
-> MkOptDescr get set a
-> OptionField a
option
            FilePath
""
            [FilePath
"tests"]
            FilePath
"Run hscolour for Test Suite targets"
            HscolourFlags -> Flag Bool
hscolourTestSuites
            (\Flag Bool
v HscolourFlags
flags -> HscolourFlags
flags{hscolourTestSuites = v})
            MkOptDescr
  (HscolourFlags -> Flag Bool)
  (Flag Bool -> HscolourFlags -> HscolourFlags)
  HscolourFlags
forall a. MkOptDescr (a -> Flag Bool) (Flag Bool -> a -> a) a
trueArg
        , FilePath
-> LFlags
-> FilePath
-> (HscolourFlags -> Flag Bool)
-> (Flag Bool -> HscolourFlags -> HscolourFlags)
-> MkOptDescr
     (HscolourFlags -> Flag Bool)
     (Flag Bool -> HscolourFlags -> HscolourFlags)
     HscolourFlags
-> OptionField HscolourFlags
forall get set a.
FilePath
-> LFlags
-> FilePath
-> get
-> set
-> MkOptDescr get set a
-> OptionField a
option
            FilePath
""
            [FilePath
"benchmarks"]
            FilePath
"Run hscolour for Benchmark targets"
            HscolourFlags -> Flag Bool
hscolourBenchmarks
            (\Flag Bool
v HscolourFlags
flags -> HscolourFlags
flags{hscolourBenchmarks = v})
            MkOptDescr
  (HscolourFlags -> Flag Bool)
  (Flag Bool -> HscolourFlags -> HscolourFlags)
  HscolourFlags
forall a. MkOptDescr (a -> Flag Bool) (Flag Bool -> a -> a) a
trueArg
        , FilePath
-> LFlags
-> FilePath
-> (HscolourFlags -> Flag Bool)
-> (Flag Bool -> HscolourFlags -> HscolourFlags)
-> MkOptDescr
     (HscolourFlags -> Flag Bool)
     (Flag Bool -> HscolourFlags -> HscolourFlags)
     HscolourFlags
-> OptionField HscolourFlags
forall get set a.
FilePath
-> LFlags
-> FilePath
-> get
-> set
-> MkOptDescr get set a
-> OptionField a
option
            FilePath
""
            [FilePath
"foreign-libraries"]
            FilePath
"Run hscolour for Foreign Library targets"
            HscolourFlags -> Flag Bool
hscolourForeignLibs
            (\Flag Bool
v HscolourFlags
flags -> HscolourFlags
flags{hscolourForeignLibs = v})
            MkOptDescr
  (HscolourFlags -> Flag Bool)
  (Flag Bool -> HscolourFlags -> HscolourFlags)
  HscolourFlags
forall a. MkOptDescr (a -> Flag Bool) (Flag Bool -> a -> a) a
trueArg
        , FilePath
-> LFlags
-> FilePath
-> (HscolourFlags -> Flag Bool)
-> (Flag Bool -> HscolourFlags -> HscolourFlags)
-> MkOptDescr
     (HscolourFlags -> Flag Bool)
     (Flag Bool -> HscolourFlags -> HscolourFlags)
     HscolourFlags
-> OptionField HscolourFlags
forall get set a.
FilePath
-> LFlags
-> FilePath
-> get
-> set
-> MkOptDescr get set a
-> OptionField a
option
            FilePath
""
            [FilePath
"all"]
            FilePath
"Run hscolour for all targets"
            ( \HscolourFlags
f ->
                [Flag Bool] -> Flag Bool
allFlags
                  [ HscolourFlags -> Flag Bool
hscolourExecutables HscolourFlags
f
                  , HscolourFlags -> Flag Bool
hscolourTestSuites HscolourFlags
f
                  , HscolourFlags -> Flag Bool
hscolourBenchmarks HscolourFlags
f
                  , HscolourFlags -> Flag Bool
hscolourForeignLibs HscolourFlags
f
                  ]
            )
            ( \Flag Bool
v HscolourFlags
flags ->
                HscolourFlags
flags
                  { hscolourExecutables = v
                  , hscolourTestSuites = v
                  , hscolourBenchmarks = v
                  , hscolourForeignLibs = v
                  }
            )
            MkOptDescr
  (HscolourFlags -> Flag Bool)
  (Flag Bool -> HscolourFlags -> HscolourFlags)
  HscolourFlags
forall a. MkOptDescr (a -> Flag Bool) (Flag Bool -> a -> a) a
trueArg
        , FilePath
-> LFlags
-> FilePath
-> (HscolourFlags -> Flag FilePath)
-> (Flag FilePath -> HscolourFlags -> HscolourFlags)
-> MkOptDescr
     (HscolourFlags -> Flag FilePath)
     (Flag FilePath -> HscolourFlags -> HscolourFlags)
     HscolourFlags
-> OptionField HscolourFlags
forall get set a.
FilePath
-> LFlags
-> FilePath
-> get
-> set
-> MkOptDescr get set a
-> OptionField a
option
            FilePath
""
            [FilePath
"css"]
            FilePath
"Use a cascading style sheet"
            HscolourFlags -> Flag FilePath
hscolourCSS
            (\Flag FilePath
v HscolourFlags
flags -> HscolourFlags
flags{hscolourCSS = v})
            (FilePath
-> MkOptDescr
     (HscolourFlags -> Flag FilePath)
     (Flag FilePath -> HscolourFlags -> HscolourFlags)
     HscolourFlags
forall b.
FilePath
-> FilePath
-> LFlags
-> FilePath
-> (b -> Flag FilePath)
-> (Flag FilePath -> b -> b)
-> OptDescr b
reqArgFlag FilePath
"PATH")
        ]
    }