blob: bd3fdd39bfe5d223249e42d78c528115d377fd50 (
plain)
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
|
module Coolbal.Options (
Options(..),
Flags(..),
Command(..),
BuildOptions(..),
RunOptions(..),
optionParser,
-- * Re-exports
Verbosity(..),
) where
import Options.Applicative
import Coolbal.Verbosity
data Options = Options Flags Command
deriving (Show)
data Flags = Flags
{ fVerbosity :: Verbosity
}
deriving (Show)
data Command
= Build BuildOptions
| Rebuild BuildOptions
| Clean
| Configure
| Run RunOptions
deriving (Show)
data BuildOptions = BuildOptions (Maybe String)
deriving (Show)
data RunOptions = RunOptions (Maybe String) [String]
deriving (Show)
optionParser :: ParserInfo Options
optionParser =
info (root <**> helper)
(fullDesc
<> header "coolbal - Faster cabal for common cases"
<> progDesc "Some simple Haskell projects don't need all the complexity of \
\Cabal's re-configuration logic. Coolbal can take an already-built \
\Cabal project and rebuild it as long as you don't change the \
\configuration too much, and as long as you don't use too-special \
\Cabal features. Always check that coolbal gives you the expected \
\result.")
root :: Parser Options
root = Options <$> parseFlags <*> parseCommand
parseFlags :: Parser Flags
parseFlags = Flags
<$> intToVerbosity . length <$> many
(flag' () (long "verbose"
<> short 'v'
<> help "Verbosity (pass multiple times to increase level)"))
parseCommand :: Parser Command
parseCommand =
hsubparser (
command "build" (info (Build <$> buildOptions)
(progDesc "Build the project"))
<> command "rebuild" (info (Rebuild <$> buildOptions)
(progDesc "Rebuild after deleting compilation artifacts for this project"))
<> command "run" (info (Run <$> runOptions)
(progDesc "Run an executable from the project"))
<> command "clean" (info (pure Clean)
(progDesc "Clean coolbal's files for this project"))
<> command "configure" (info (pure Configure)
(progDesc "Initialise coolbal for this project")))
buildOptions :: Parser BuildOptions
buildOptions = BuildOptions <$> optional (argument str (metavar "TARGET"))
runOptions :: Parser RunOptions
runOptions = RunOptions <$> optional (argument str (metavar "TARGET")) <*> many (argument str (metavar "ARGS..."))
|