Types.hs 3.72 KB
Newer Older
1 2 3
{-# language GeneralizedNewtypeDeriving #-}
{-# language OverloadedStrings #-}

Valentin Reis's avatar
types.  
Valentin Reis committed
4 5 6 7 8 9 10 11
{-|
Module      : Argo.Types
Description : types for running argo stacks
Copyright   : (c) Valentin Reis, 2018
License     : MIT
Maintainer  : fre@freux.fr
-}

12 13 14 15 16 17 18 19 20 21 22 23
module Argo.Types
  ( StdOutLog(..)
  , StdErrLog(..)
  , TestText(..)
  , ProcessBehavior(..)
  , TextBehavior(..)
  , TextBehaviorStdout(..)
  , TextBehaviorStderr(..)
  , WorkingDirectory(..)
  , Verbosity(..)
  , AppName(..)
  , AppArg(..)
24
  , EnvVar(..)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  , ContainerName(..)
  , ShareDir(..)
  , ManifestName(..)
  , StackArgs(..)
  , PreludeCommand(..)
  , HwThreadCount(..)
  , PowerCap(..)
  , toOption
  )
where

import           Data.Default
import           Data.Text                     as T
                                         hiding ( empty )
import           Turtle                  hiding ( option )
import           Prelude                 hiding ( FilePath )

data StackArgs = StackArgs
  { verbosity              :: Verbosity
  , app                    :: AppName
45
  , vars                   :: [(EnvVar,Text)]
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  , args                   :: [AppArg]
  , containerName          :: ContainerName
  , workingDirectory       :: WorkingDirectory
  , shareDir               :: ShareDir
  , manifestName           :: ManifestName
  , preludeCommand         :: PreludeCommand
  , daemon
  , cmdrun
  , cmdlisten
  , cmdlistenprogress
  , cmdlistenperformance
  , cmdlistenpower         :: ProcessBehavior
  , hwThreadCount          :: HwThreadCount
  , powercap               :: PowerCap
  } deriving (Show)

{-data OutputFiles = OutputFiles FilePath FilePath-}
data Verbosity = Normal | Verbose deriving (Show, Read, Eq)
64
newtype EnvVar = EnvVar Text deriving (Show, Read)
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
newtype HwThreadCount = HwThreadCount Int deriving (Show, Read, Eq)
newtype AppArg = AppArg Text deriving (IsString, Show, Read)
newtype WorkingDirectory = WorkingDirectory FilePath deriving (IsString, Show)
newtype AppName = AppName Text deriving (IsString, Show, Read)
newtype ContainerName = ContainerName Text deriving (IsString, Show, Read)
newtype ShareDir = ShareDir FilePath deriving (IsString, Show)
newtype ManifestName = ManifestName FilePath deriving (IsString, Show)
newtype PreludeCommand = PreludeCommand Text deriving (IsString, Show, Read)
data ProcessBehavior =
     Test TestText StdOutLog StdErrLog
   | JustRun StdOutLog StdErrLog
   | DontRun deriving (Show,Read)
newtype StdOutLog = StdOutLog Text deriving (Show, Read)
newtype StdErrLog = StdErrLog Text deriving (Show, Read)
data TestText = TestText TextBehaviorStdout TextBehaviorStderr deriving (Show, Read)
newtype TextBehaviorStdout = TextBehaviorStdout TextBehavior deriving (Show, Read)
newtype TextBehaviorStderr = TextBehaviorStderr TextBehavior deriving (Show, Read)
data TextBehavior =
    WaitFor Text
  | ExpectClean deriving (Show,Read)
85
data PowerCap = Fixed Int | Adaptive | None deriving (Show, Read, Eq)
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102

class ToDaemonOption a where
  toOption :: a -> [String]

instance ToDaemonOption Verbosity where
  toOption Verbose = ["--verbose"]
  toOption Normal = []

instance ToDaemonOption PowerCap where
  toOption (Fixed i) = ["--powercap", show i]
  toOption Adaptive = []
  toOption None = []

instance Default StackArgs where
  def = StackArgs
    { verbosity = Normal
    , app = AppName "ls"
103
    , vars = []
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    , args = []
    , containerName = ContainerName "testContainer"
    , workingDirectory = WorkingDirectory "_output"
    , shareDir = ShareDir "/tmp"
    , manifestName = ManifestName "basic.json"
    , preludeCommand = PreludeCommand ""
    , daemon = DontRun
    , cmdrun = DontRun
    , cmdlisten = DontRun
    , cmdlistenprogress = DontRun
    , cmdlistenperformance = DontRun
    , cmdlistenpower = DontRun
    , hwThreadCount = HwThreadCount 1
    , powercap = None
    }