aboutsummaryrefslogtreecommitdiff
path: root/tests/TestOptions.hs
blob: 0504f8fcb4a62f0612aeaa181d52e6ece7cf6d06 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module TestOptions
    ( ModProgs
    , testOpts
    ) where

import System.Console.GetOpt as GetOpt

import CabalHelper.Compiletime.Types

type ModProgs = (Programs -> Programs)

options :: [OptDescr ModProgs]
options =
    [ GetOpt.Option [] ["with-cabal"]
        (ReqArg (\arg -> \p -> p { cabalProgram = arg }) "PROG")
        "name or path of 'cabal' executable"
    , GetOpt.Option [] ["with-stack"]
        (ReqArg (\arg -> \p -> p { stackProgram = arg }) "PROG")
        "name or path of 'stack' executable"
    , GetOpt.Option [] ["with-ghc"]
        (ReqArg (\arg -> \cp -> cp { ghcProgram = arg }) "PROG")
        "name or path of 'ghc' executable"
    , GetOpt.Option [] ["with-ghc-pkg"]
        (ReqArg (\arg -> \cp -> cp { ghcPkgProgram = arg }) "PROG")
        "name or path of 'ghc-pkg' executable"
    ]

testOpts :: [String] -> IO (ModProgs, [String])
testOpts args =
   case getOpt Permute options args of
      (o,n,[]  ) -> return (foldl (flip (.)) id o, n)
      (_,_,errs) -> ioError (userError (concat errs ++ usageInfo header options))
  where header = "Usage: ghc-session [OPTION..] [TEST_SPEC..]"