{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module Aura.Settings
( Settings(..)
, BuildConfig(..), BuildSwitch(..)
, switch
, Truncation(..)
, defaultBuildDir
, CommonConfig(..), CommonSwitch(..)
, ColourMode(..)
, shared
, Makepkg(..)
) where
import Aura.Types
import Network.HTTP.Client (Manager)
import RIO
import qualified RIO.Set as S
import qualified RIO.Text as T
import System.Path (Absolute, Path, fromAbsoluteFilePath, toFilePath)
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 :: !(Set CommonSwitch) } deriving (Show, Generic)
instance Flagable CommonConfig where
asFlag (CommonConfig cap cop lfp cs) =
either (const []) (\p -> ["--cachedir", T.pack $ toFilePath p]) cap
<> either (const []) (\p -> ["--config", T.pack $ toFilePath p]) cop
<> either (const []) (\p -> ["--logfile", T.pack $ 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 :: !(Set Makepkg)
, buildPathOf :: !(Path Absolute)
, buildUserOf :: !(Maybe User)
, truncationOf :: !Truncation
, buildSwitchesOf :: !(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 :: !(Set PkgName)
, commonConfigOf :: !CommonConfig
, buildConfigOf :: !BuildConfig }
defaultBuildDir :: Path Absolute
defaultBuildDir = fromAbsoluteFilePath "/tmp"