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

module Stack.Types.SCM
  ( SCM (..)
  ) where

import           Data.Aeson.Types ( FromJSON (..), ToJSON (..) )
import           Stack.Prelude

-- | A software control system.

data SCM
  = Git
  deriving Int -> SCM -> ShowS
[SCM] -> ShowS
SCM -> String
(Int -> SCM -> ShowS)
-> (SCM -> String) -> ([SCM] -> ShowS) -> Show SCM
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SCM -> ShowS
showsPrec :: Int -> SCM -> ShowS
$cshow :: SCM -> String
show :: SCM -> String
$cshowList :: [SCM] -> ShowS
showList :: [SCM] -> ShowS
Show

instance FromJSON SCM where
  parseJSON :: Value -> Parser SCM
parseJSON Value
v = do
    String
s <- Value -> Parser String
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v
    case String
s of
      String
"git" -> SCM -> Parser SCM
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SCM
Git
      String
_ -> String -> Parser SCM
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Unknown or unsupported SCM: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
s)

instance ToJSON SCM where
  toJSON :: SCM -> Value
toJSON SCM
Git = Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text
"git" :: Text)