{-# LANGUAGE NoImplicitPrelude #-}

module Stack.Options.HaddockParser
  ( haddockOptsParser
  ) where

import           Options.Applicative ( Parser, help, long, metavar )
import           Options.Applicative.Args ( argsOption )
import           Stack.Options.Utils ( hideMods )
import           Stack.Prelude
import           Stack.Types.BuildOpts ( HaddockOptsMonoid (..) )

-- | Parser for haddock arguments.

haddockOptsParser :: Bool -> Parser HaddockOptsMonoid
haddockOptsParser :: Bool -> Parser HaddockOptsMonoid
haddockOptsParser Bool
hide0 = [String] -> HaddockOptsMonoid
HaddockOptsMonoid
  ([String] -> HaddockOptsMonoid)
-> Parser [String] -> Parser HaddockOptsMonoid
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Maybe [String] -> [String])
-> Parser (Maybe [String]) -> Parser [String]
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
        ([String] -> Maybe [String] -> [String]
forall a. a -> Maybe a -> a
fromMaybe [])
        ( Parser [String] -> Parser (Maybe [String])
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Mod OptionFields [String] -> Parser [String]
argsOption
            (  String -> Mod OptionFields [String]
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"haddock-arguments"
            Mod OptionFields [String]
-> Mod OptionFields [String] -> Mod OptionFields [String]
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields [String]
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"HADDOCK_ARGS"
            Mod OptionFields [String]
-> Mod OptionFields [String] -> Mod OptionFields [String]
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields [String]
forall (f :: * -> *) a. String -> Mod f a
help String
"Arguments passed to the Haddock program."
            Mod OptionFields [String]
-> Mod OptionFields [String] -> Mod OptionFields [String]
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields [String]
forall {f :: * -> *} {a}. Mod f a
hide
            ))
        )
 where
  hide :: Mod f a
hide = Bool -> Mod f a
forall (f :: * -> *) a. Bool -> Mod f a
hideMods Bool
hide0