{-# LANGUAGE NoImplicitPrelude #-}

module Stack.Options.Utils
  ( GlobalOptsContext (..)
  , hideMods
  ) where

import           Options.Applicative ( Mod, hidden, idm, internal )
import           Stack.Prelude

-- | If argument is True, hides the option from usage and help

hideMods :: Bool -> Mod f a
hideMods :: forall (f :: * -> *) a. Bool -> Mod f a
hideMods Bool
hide = if Bool
hide then forall (f :: * -> *) a. Mod f a
internal forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Mod f a
hidden else forall m. Monoid m => m
idm

-- | Allows adjust global options depending on their context

-- Note: This was being used to remove ambiguity between the local and global

-- implementation of stack init --resolver option. Now that stack init has no

-- local --resolver this is not being used anymore but the code is kept for any

-- similar future use cases.

data GlobalOptsContext
  = OuterGlobalOpts -- ^ Global options before subcommand name

  | OtherCmdGlobalOpts -- ^ Global options following any other subcommand

  | BuildCmdGlobalOpts
  | GhciCmdGlobalOpts
  deriving (GlobalOptsContext -> GlobalOptsContext -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GlobalOptsContext -> GlobalOptsContext -> Bool
$c/= :: GlobalOptsContext -> GlobalOptsContext -> Bool
== :: GlobalOptsContext -> GlobalOptsContext -> Bool
$c== :: GlobalOptsContext -> GlobalOptsContext -> Bool
Eq, Int -> GlobalOptsContext -> ShowS
[GlobalOptsContext] -> ShowS
GlobalOptsContext -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GlobalOptsContext] -> ShowS
$cshowList :: [GlobalOptsContext] -> ShowS
show :: GlobalOptsContext -> String
$cshow :: GlobalOptsContext -> String
showsPrec :: Int -> GlobalOptsContext -> ShowS
$cshowsPrec :: Int -> GlobalOptsContext -> ShowS
Show)