{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}

module Stack.Options.BenchParser
 ( benchOptsParser
 ) where

import           Options.Applicative
                   ( Parser, flag', help, long, metavar, strOption )
import           Options.Applicative.Builder.Extra ( optionalFirst )
import           Stack.Prelude
import           Stack.Options.Utils ( hideMods )
import           Stack.Types.BuildOpts ( BenchmarkOptsMonoid (..) )

-- | Parser for bench arguments.

-- FIXME hiding options

benchOptsParser :: Bool -> Parser BenchmarkOptsMonoid
benchOptsParser :: Bool -> Parser BenchmarkOptsMonoid
benchOptsParser Bool
hide0 = First String -> First Bool -> BenchmarkOptsMonoid
BenchmarkOptsMonoid
  (First String -> First Bool -> BenchmarkOptsMonoid)
-> Parser (First String)
-> Parser (First Bool -> BenchmarkOptsMonoid)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser String -> Parser (First String)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
        (  String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"benchmark-arguments"
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"ba"
        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
"BENCH_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
"Forward BENCH_ARGS to the benchmark suite. Supports templates \
                \from 'cabal bench'."
        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
        ))
  Parser (First Bool -> BenchmarkOptsMonoid)
-> Parser (First Bool) -> Parser BenchmarkOptsMonoid
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Bool -> Parser (First Bool)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (Bool -> Mod FlagFields Bool -> Parser Bool
forall a. a -> Mod FlagFields a -> Parser a
flag' Bool
True
        (  String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"no-run-benchmarks"
        Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
help String
"Disable running of benchmarks. (Benchmarks will still be \
                \built.)"
        Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> Mod FlagFields Bool
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