forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArgs.hs
More file actions
38 lines (32 loc) · 1.34 KB
/
Args.hs
File metadata and controls
38 lines (32 loc) · 1.34 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
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
-- | Accepting arguments to be passed through to a sub-process.
module Options.Applicative.Args
(argsArgument
,argsOption
,cmdOption)
where
import Data.Attoparsec.Args
import qualified Options.Applicative as O
import Stack.Prelude
-- | An argument which accepts a list of arguments e.g. @--ghc-options="-X P.hs \"this\""@.
argsArgument :: O.Mod O.ArgumentFields [String] -> O.Parser [String]
argsArgument =
O.argument
(do string <- O.str
either O.readerError return (parseArgsFromString Escaping string))
-- | An option which accepts a list of arguments e.g. @--ghc-options="-X P.hs \"this\""@.
argsOption :: O.Mod O.OptionFields [String] -> O.Parser [String]
argsOption =
O.option
(do string <- O.str
either O.readerError return (parseArgsFromString Escaping string))
-- | An option which accepts a command and a list of arguments e.g. @--exec "echo hello world"@
cmdOption :: O.Mod O.OptionFields (String, [String]) -> O.Parser (String, [String])
cmdOption =
O.option
(do string <- O.str
xs <- either O.readerError return (parseArgsFromString Escaping string)
case xs of
[] -> O.readerError "Must provide a command"
x:xs' -> return (x, xs'))