forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptParser.hs
More file actions
84 lines (78 loc) · 2.31 KB
/
Copy pathScriptParser.hs
File metadata and controls
84 lines (78 loc) · 2.31 KB
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
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
82
83
84
{-# LANGUAGE NoImplicitPrelude #-}
module Stack.Options.ScriptParser
( ScriptExecute (..)
, ScriptOpts (..)
, ShouldRun (..)
, scriptOptsParser
) where
import Options.Applicative
( Parser, completer, eitherReader, flag', help, long
, metavar, option, strArgument, strOption
)
import Options.Applicative.Builder.Extra ( fileExtCompleter )
import Stack.Options.Completion ( ghcOptsCompleter )
import Stack.Prelude
data ScriptOpts = ScriptOpts
{ soPackages :: ![String]
, soFile :: !FilePath
, soArgs :: ![String]
, soCompile :: !ScriptExecute
, soGhcOptions :: ![String]
, soScriptExtraDeps :: ![PackageIdentifierRevision]
, soShouldRun :: !ShouldRun
}
deriving Show
data ScriptExecute
= SEInterpret
| SECompile
| SEOptimize
deriving Show
data ShouldRun
= YesRun
| NoRun
deriving Show
scriptOptsParser :: Parser ScriptOpts
scriptOptsParser = ScriptOpts
<$> many (strOption
( long "package"
<> metavar "PACKAGE"
<> help "Add a package (can be specified multiple times)"
))
<*> strArgument
( metavar "FILE"
<> completer (fileExtCompleter [".hs", ".lhs"])
)
<*> many (strArgument
( metavar "-- ARGUMENT(S) (e.g. stack script X.hs -- argument(s) to \
\program)"
))
<*> ( flag' SECompile
( long "compile"
<> help "Compile the script without optimization and run the executable"
)
<|> flag' SEOptimize
( long "optimize"
<> help "Compile the script with optimization and run the executable"
)
<|> pure SEInterpret
)
<*> many (strOption
( long "ghc-options"
<> metavar "OPTIONS"
<> completer ghcOptsCompleter
<> help "Additional options passed to GHC"
))
<*> many (option extraDepRead
( long "extra-dep"
<> metavar "PACKAGE-VERSION"
<> help "Extra dependencies to be added to the snapshot"
))
<*> ( flag' NoRun
( long "no-run"
<> help "Don't run, just compile."
)
<|> pure YesRun
)
where
extraDepRead = eitherReader $
mapLeft show . parsePackageIdentifierRevision . fromString