{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
module Aura.Settings
( Settings(..)
, BuildConfig(..), BuildSwitch(..)
, switch
, Truncation(..)
, defaultBuildDir
, CommonConfig(..), CommonSwitch(..)
, ColourMode(..)
, shared
, Makepkg(..)
) where
import Aura.Types
import BasePrelude
import qualified Data.Set as S
import Network.HTTP.Client (Manager)
import System.Path (Path, Absolute, toFilePath, fromAbsoluteFilePath)
data Truncation = None | Head Word | Tail Word deriving (Eq, Show)
data Makepkg = IgnoreArch | AllSource | SkipInteg deriving (Eq, Ord, Show)
instance Flagable Makepkg where
asFlag IgnoreArch = ["--ignorearch"]
asFlag AllSource = ["--allsource"]
asFlag SkipInteg = ["--skipinteg"]
data CommonConfig = CommonConfig { cachePathOf :: !(Either (Path Absolute) (Path Absolute))
, configPathOf :: !(Either (Path Absolute) (Path Absolute))
, logPathOf :: !(Either (Path Absolute) (Path Absolute))
, commonSwitchesOf :: !(S.Set CommonSwitch) } deriving (Show, Generic)
instance Flagable CommonConfig where
asFlag (CommonConfig cap cop lfp cs) =
either (const []) (\p -> ["--cachedir", toFilePath p]) cap
++ either (const []) (\p -> ["--config", toFilePath p]) cop
++ either (const []) (\p -> ["--logfile", toFilePath p]) lfp
++ asFlag cs
data CommonSwitch = NoConfirm | NeededOnly | Debug | Colour ColourMode deriving (Eq, Ord, Show)
instance Flagable CommonSwitch where
asFlag NoConfirm = ["--noconfirm"]
asFlag NeededOnly = ["--needed"]
asFlag Debug = ["--debug"]
asFlag (Colour m) = "--color" : asFlag m
data ColourMode = Never | Always | Auto deriving (Eq, Ord, Show)
instance Flagable ColourMode where
asFlag Never = ["never"]
asFlag Always = ["always"]
asFlag Auto = ["auto"]
data BuildConfig = BuildConfig { makepkgFlagsOf :: !(S.Set Makepkg)
, buildPathOf :: !(Path Absolute)
, buildUserOf :: !(Maybe User)
, truncationOf :: !Truncation
, buildSwitchesOf :: !(S.Set BuildSwitch) } deriving (Show)
data BuildSwitch = DeleteMakeDeps
| DiffPkgbuilds
| DontSuppressMakepkg
| DryRun
| HotEdit
| LowVerbosity
| RebuildDevel
| SortAlphabetically
| UseCustomizepkg
| ForceBuilding
| NoPkgbuildCheck
deriving (Eq, Ord, Show)
switch :: Settings -> BuildSwitch -> Bool
switch ss bs = S.member bs . buildSwitchesOf $ buildConfigOf ss
shared :: Settings -> CommonSwitch -> Bool
shared ss c = S.member c . commonSwitchesOf $ commonConfigOf ss
data Settings = Settings { managerOf :: !Manager
, envOf :: !Environment
, langOf :: !Language
, editorOf :: !FilePath
, isTerminal :: !Bool
, ignoresOf :: !(S.Set PkgName)
, commonConfigOf :: !CommonConfig
, buildConfigOf :: !BuildConfig }
defaultBuildDir :: Path Absolute
defaultBuildDir = fromAbsoluteFilePath "/tmp"