{-# LANGUAGE NoImplicitPrelude     #-}
{-# LANGUAGE NoFieldSelectors      #-}

{-|
Module      : Stack.Types.ConfigSetOpts
Description : Types related to Stack's @config set@ command.
License     : BSD-3-Clause

Types related to Stack's @config set@ command.
-}

module Stack.Types.ConfigSetOpts
  ( ConfigCmdSet (..)
  , CommandScope (..)
  , configCmdSetScope
  ) where

import           Stack.Prelude
import           Stack.Types.Snapshot ( AbstractSnapshot )

-- | Type representing options for Stack's @config set@ command.

data ConfigCmdSet
  = ConfigCmdSetSnapshot !(Unresolved AbstractSnapshot)
  | ConfigCmdSetResolver !(Unresolved AbstractSnapshot)
  | ConfigCmdSetSystemGhc !CommandScope !Bool
  | ConfigCmdSetInstallGhc !CommandScope !Bool
  | ConfigCmdSetInstallMsys !CommandScope !Bool
  | ConfigCmdSetRecommendStackUpgrade !CommandScope !Bool
  | ConfigCmdSetDownloadPrefix !CommandScope !Text

-- | Type representing scopes for Stack's @config set@ command.

data CommandScope
  = CommandScopeGlobal
    -- ^ Apply changes to Stack's global configuration file.

  | CommandScopeProject
    -- ^ Apply changes to Stack's project-level configuration file.


-- | Yields the command scope for the given config command option.

configCmdSetScope :: ConfigCmdSet -> CommandScope
configCmdSetScope :: ConfigCmdSet -> CommandScope
configCmdSetScope (ConfigCmdSetSnapshot Unresolved AbstractSnapshot
_) = CommandScope
CommandScopeProject
configCmdSetScope (ConfigCmdSetResolver Unresolved AbstractSnapshot
_) = CommandScope
CommandScopeProject
configCmdSetScope (ConfigCmdSetSystemGhc CommandScope
scope Bool
_) = CommandScope
scope
configCmdSetScope (ConfigCmdSetInstallGhc CommandScope
scope Bool
_) = CommandScope
scope
configCmdSetScope (ConfigCmdSetInstallMsys CommandScope
scope Bool
_) = CommandScope
scope
configCmdSetScope (ConfigCmdSetRecommendStackUpgrade CommandScope
scope Bool
_) = CommandScope
scope
configCmdSetScope (ConfigCmdSetDownloadPrefix CommandScope
scope Text
_) = CommandScope
scope