{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ViewPatterns #-}

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

-- |
-- 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
      ( HscolourCommonFlags
      , hscolourVerbosity
      , hscolourDistPref
      , hscolourCabalFilePath
      , hscolourWorkingDir
      , hscolourTargets
      , ..
      )
  , 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.Simple.Setup.Common
import Distribution.Utils.Path
import Distribution.Verbosity

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

-- * HsColour flags

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

data HscolourFlags = HscolourFlags
  { HscolourFlags -> CommonSetupFlags
hscolourCommonFlags :: !CommonSetupFlags
  , 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
  }
  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)

pattern HscolourCommonFlags
  :: Flag Verbosity
  -> Flag (SymbolicPath Pkg (Dir Dist))
  -> Flag (SymbolicPath CWD (Dir Pkg))
  -> Flag (SymbolicPath Pkg File)
  -> [String]
  -> HscolourFlags
pattern $mHscolourCommonFlags :: forall {r}.
HscolourFlags
-> (Flag Verbosity
    -> Flag (SymbolicPath Pkg ('Dir Dist))
    -> Flag (SymbolicPath CWD ('Dir Pkg))
    -> Flag (SymbolicPath Pkg 'File)
    -> [FilePath]
    -> r)
-> ((# #) -> r)
-> r
HscolourCommonFlags
  { HscolourFlags -> Flag Verbosity
hscolourVerbosity
  , HscolourFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
hscolourDistPref
  , HscolourFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
hscolourWorkingDir
  , HscolourFlags -> Flag (SymbolicPath Pkg 'File)
hscolourCabalFilePath
  , HscolourFlags -> [FilePath]
hscolourTargets
  } <-
  ( hscolourCommonFlags ->
      CommonSetupFlags
        { setupVerbosity = hscolourVerbosity
        , setupDistPref = hscolourDistPref
        , setupWorkingDir = hscolourWorkingDir
        , setupCabalFilePath = hscolourCabalFilePath
        , setupTargets = hscolourTargets
        }
    )

instance Binary HscolourFlags
instance Structured HscolourFlags

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

defaultHscolourFlags :: HscolourFlags
defaultHscolourFlags :: HscolourFlags
defaultHscolourFlags =
  HscolourFlags
    { hscolourCommonFlags :: CommonSetupFlags
hscolourCommonFlags = CommonSetupFlags
defaultCommonSetupFlags
    , 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
    , hscolourForeignLibs :: Flag Bool
hscolourForeignLibs = Bool -> Flag Bool
forall a. a -> Flag a
Flag Bool
False
    }

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 -> CommonSetupFlags)
-> (CommonSetupFlags -> HscolourFlags -> HscolourFlags)
-> ShowOrParseArgs
-> [OptionField HscolourFlags]
-> [OptionField HscolourFlags]
forall flags.
(flags -> CommonSetupFlags)
-> (CommonSetupFlags -> flags -> flags)
-> ShowOrParseArgs
-> [OptionField flags]
-> [OptionField flags]
withCommonSetupOptions
          HscolourFlags -> CommonSetupFlags
hscolourCommonFlags
          (\CommonSetupFlags
c HscolourFlags
f -> HscolourFlags
f{hscolourCommonFlags = c})
          ShowOrParseArgs
showOrParseArgs
          [ FilePath
-> [FilePath]
-> FilePath
-> (HscolourFlags -> Flag Bool)
-> (Flag Bool -> HscolourFlags -> HscolourFlags)
-> MkOptDescr
     (HscolourFlags -> Flag Bool)
     (Flag Bool -> HscolourFlags -> HscolourFlags)
     HscolourFlags
-> OptionField HscolourFlags
forall get set a.
FilePath
-> [FilePath]
-> 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
-> [FilePath]
-> FilePath
-> (HscolourFlags -> Flag Bool)
-> (Flag Bool -> HscolourFlags -> HscolourFlags)
-> MkOptDescr
     (HscolourFlags -> Flag Bool)
     (Flag Bool -> HscolourFlags -> HscolourFlags)
     HscolourFlags
-> OptionField HscolourFlags
forall get set a.
FilePath
-> [FilePath]
-> 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
-> [FilePath]
-> FilePath
-> (HscolourFlags -> Flag Bool)
-> (Flag Bool -> HscolourFlags -> HscolourFlags)
-> MkOptDescr
     (HscolourFlags -> Flag Bool)
     (Flag Bool -> HscolourFlags -> HscolourFlags)
     HscolourFlags
-> OptionField HscolourFlags
forall get set a.
FilePath
-> [FilePath]
-> 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
-> [FilePath]
-> FilePath
-> (HscolourFlags -> Flag Bool)
-> (Flag Bool -> HscolourFlags -> HscolourFlags)
-> MkOptDescr
     (HscolourFlags -> Flag Bool)
     (Flag Bool -> HscolourFlags -> HscolourFlags)
     HscolourFlags
-> OptionField HscolourFlags
forall get set a.
FilePath
-> [FilePath]
-> 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
-> [FilePath]
-> FilePath
-> (HscolourFlags -> Flag Bool)
-> (Flag Bool -> HscolourFlags -> HscolourFlags)
-> MkOptDescr
     (HscolourFlags -> Flag Bool)
     (Flag Bool -> HscolourFlags -> HscolourFlags)
     HscolourFlags
-> OptionField HscolourFlags
forall get set a.
FilePath
-> [FilePath]
-> 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
-> [FilePath]
-> FilePath
-> (HscolourFlags -> Flag FilePath)
-> (Flag FilePath -> HscolourFlags -> HscolourFlags)
-> MkOptDescr
     (HscolourFlags -> Flag FilePath)
     (Flag FilePath -> HscolourFlags -> HscolourFlags)
     HscolourFlags
-> OptionField HscolourFlags
forall get set a.
FilePath
-> [FilePath]
-> 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
-> [FilePath]
-> FilePath
-> (b -> Flag FilePath)
-> (Flag FilePath -> b -> b)
-> OptDescr b
reqArgFlag FilePath
"PATH")
          ]
    }