Types.hs 3.6 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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
module Argo.Types
  ( StdOutLog(..)
  , StdErrLog(..)
  , TestText(..)
  , ProcessBehavior(..)
  , TextBehavior(..)
  , TextBehaviorStdout(..)
  , TextBehaviorStderr(..)
  , WorkingDirectory(..)
  , Verbosity(..)
  , AppName(..)
  , AppArg(..)
  , 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
  , 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)
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)
82
data PowerCap = Fixed Int | Adaptive | None deriving (Show, Read, Eq)
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115

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"
    , 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
    }