module Argo.Type.Settings where

import qualified Argo.Type.Flag as Flag
import qualified Argo.Type.Indent as Indent
import qualified Text.Read as Read

data Settings = Settings
    { Settings -> Bool
help :: Bool
    , Settings -> Indent
indent :: Indent.Indent
    , Settings -> Bool
version :: Bool
    }
    deriving (Settings -> Settings -> Bool
(Settings -> Settings -> Bool)
-> (Settings -> Settings -> Bool) -> Eq Settings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Settings -> Settings -> Bool
$c/= :: Settings -> Settings -> Bool
== :: Settings -> Settings -> Bool
$c== :: Settings -> Settings -> Bool
Eq, Int -> Settings -> ShowS
[Settings] -> ShowS
Settings -> String
(Int -> Settings -> ShowS)
-> (Settings -> String) -> ([Settings] -> ShowS) -> Show Settings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Settings] -> ShowS
$cshowList :: [Settings] -> ShowS
show :: Settings -> String
$cshow :: Settings -> String
showsPrec :: Int -> Settings -> ShowS
$cshowsPrec :: Int -> Settings -> ShowS
Show)

initial :: Settings
initial :: Settings
initial = Settings :: Bool -> Indent -> Bool -> Settings
Settings { help :: Bool
help = Bool
False, indent :: Indent
indent = Int -> Indent
Indent.Spaces Int
0, version :: Bool
version = Bool
False }

applyFlag :: Settings -> Flag.Flag -> Either String Settings
applyFlag :: Settings -> Flag -> Either String Settings
applyFlag Settings
settings Flag
flag = case Flag
flag of
    Flag
Flag.Help -> Settings -> Either String Settings
forall (f :: * -> *) a. Applicative f => a -> f a
pure Settings
settings { help :: Bool
help = Bool
True }
    Flag.Spaces String
string -> do
        Int
int <- String -> Either String Int
forall a. Read a => String -> Either String a
Read.readEither String
string
        Settings -> Either String Settings
forall (f :: * -> *) a. Applicative f => a -> f a
pure Settings
settings { indent :: Indent
indent = Int -> Indent
Indent.Spaces Int
int }
    Flag
Flag.Tab -> Settings -> Either String Settings
forall (f :: * -> *) a. Applicative f => a -> f a
pure Settings
settings { indent :: Indent
indent = Indent
Indent.Tab }
    Flag
Flag.Version -> Settings -> Either String Settings
forall (f :: * -> *) a. Applicative f => a -> f a
pure Settings
settings { version :: Bool
version = Bool
True }