{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module HaskellCI.Config.CopyFields where

import HaskellCI.Prelude

import qualified Distribution.Compat.CharParsing as C
import qualified Distribution.Parsec             as C
import qualified Distribution.Pretty             as C
import qualified Text.PrettyPrint                as PP

data CopyFields
    = CopyFieldsNone
    | CopyFieldsSome
    | CopyFieldsAll
  deriving (CopyFields -> CopyFields -> Bool
(CopyFields -> CopyFields -> Bool)
-> (CopyFields -> CopyFields -> Bool) -> Eq CopyFields
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CopyFields -> CopyFields -> Bool
$c/= :: CopyFields -> CopyFields -> Bool
== :: CopyFields -> CopyFields -> Bool
$c== :: CopyFields -> CopyFields -> Bool
Eq, Eq CopyFields
Eq CopyFields
-> (CopyFields -> CopyFields -> Ordering)
-> (CopyFields -> CopyFields -> Bool)
-> (CopyFields -> CopyFields -> Bool)
-> (CopyFields -> CopyFields -> Bool)
-> (CopyFields -> CopyFields -> Bool)
-> (CopyFields -> CopyFields -> CopyFields)
-> (CopyFields -> CopyFields -> CopyFields)
-> Ord CopyFields
CopyFields -> CopyFields -> Bool
CopyFields -> CopyFields -> Ordering
CopyFields -> CopyFields -> CopyFields
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CopyFields -> CopyFields -> CopyFields
$cmin :: CopyFields -> CopyFields -> CopyFields
max :: CopyFields -> CopyFields -> CopyFields
$cmax :: CopyFields -> CopyFields -> CopyFields
>= :: CopyFields -> CopyFields -> Bool
$c>= :: CopyFields -> CopyFields -> Bool
> :: CopyFields -> CopyFields -> Bool
$c> :: CopyFields -> CopyFields -> Bool
<= :: CopyFields -> CopyFields -> Bool
$c<= :: CopyFields -> CopyFields -> Bool
< :: CopyFields -> CopyFields -> Bool
$c< :: CopyFields -> CopyFields -> Bool
compare :: CopyFields -> CopyFields -> Ordering
$ccompare :: CopyFields -> CopyFields -> Ordering
$cp1Ord :: Eq CopyFields
Ord, Int -> CopyFields -> ShowS
[CopyFields] -> ShowS
CopyFields -> String
(Int -> CopyFields -> ShowS)
-> (CopyFields -> String)
-> ([CopyFields] -> ShowS)
-> Show CopyFields
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CopyFields] -> ShowS
$cshowList :: [CopyFields] -> ShowS
show :: CopyFields -> String
$cshow :: CopyFields -> String
showsPrec :: Int -> CopyFields -> ShowS
$cshowsPrec :: Int -> CopyFields -> ShowS
Show, Int -> CopyFields
CopyFields -> Int
CopyFields -> [CopyFields]
CopyFields -> CopyFields
CopyFields -> CopyFields -> [CopyFields]
CopyFields -> CopyFields -> CopyFields -> [CopyFields]
(CopyFields -> CopyFields)
-> (CopyFields -> CopyFields)
-> (Int -> CopyFields)
-> (CopyFields -> Int)
-> (CopyFields -> [CopyFields])
-> (CopyFields -> CopyFields -> [CopyFields])
-> (CopyFields -> CopyFields -> [CopyFields])
-> (CopyFields -> CopyFields -> CopyFields -> [CopyFields])
-> Enum CopyFields
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: CopyFields -> CopyFields -> CopyFields -> [CopyFields]
$cenumFromThenTo :: CopyFields -> CopyFields -> CopyFields -> [CopyFields]
enumFromTo :: CopyFields -> CopyFields -> [CopyFields]
$cenumFromTo :: CopyFields -> CopyFields -> [CopyFields]
enumFromThen :: CopyFields -> CopyFields -> [CopyFields]
$cenumFromThen :: CopyFields -> CopyFields -> [CopyFields]
enumFrom :: CopyFields -> [CopyFields]
$cenumFrom :: CopyFields -> [CopyFields]
fromEnum :: CopyFields -> Int
$cfromEnum :: CopyFields -> Int
toEnum :: Int -> CopyFields
$ctoEnum :: Int -> CopyFields
pred :: CopyFields -> CopyFields
$cpred :: CopyFields -> CopyFields
succ :: CopyFields -> CopyFields
$csucc :: CopyFields -> CopyFields
Enum, CopyFields
CopyFields -> CopyFields -> Bounded CopyFields
forall a. a -> a -> Bounded a
maxBound :: CopyFields
$cmaxBound :: CopyFields
minBound :: CopyFields
$cminBound :: CopyFields
Bounded)

-------------------------------------------------------------------------------
-- Functions
-------------------------------------------------------------------------------

showCopyFields :: CopyFields -> String
showCopyFields :: CopyFields -> String
showCopyFields CopyFields
CopyFieldsNone = String
"none"
showCopyFields CopyFields
CopyFieldsSome = String
"some"
showCopyFields CopyFields
CopyFieldsAll  = String
"all"

instance C.Pretty CopyFields where
    pretty :: CopyFields -> Doc
pretty = String -> Doc
PP.text (String -> Doc) -> (CopyFields -> String) -> CopyFields -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CopyFields -> String
showCopyFields

instance C.Parsec CopyFields where
    parsec :: m CopyFields
parsec = [m CopyFields] -> m CopyFields
forall (m :: * -> *) a. Alternative m => [m a] -> m a
C.choice
        [ CopyFields
f CopyFields -> m String -> m CopyFields
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
C.string (CopyFields -> String
showCopyFields CopyFields
f)
        | CopyFields
f <- [ CopyFields
forall a. Bounded a => a
minBound .. CopyFields
forall a. Bounded a => a
maxBound ]
        ]