Skip to content

Commit 99f5885

Browse files
committed
Add explicit import lists to Options.DotParser
Also, some reformatting
1 parent 98734d2 commit 99f5885

File tree

1 file changed

+102
-67
lines changed

1 file changed

+102
-67
lines changed

src/Stack/Options/DotParser.hs

Lines changed: 102 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -9,73 +9,96 @@ import qualified Data.Set as Set
99
import qualified Data.Text as T
1010
import Distribution.Types.PackageName ( mkPackageName )
1111
import Options.Applicative
12-
import Options.Applicative.Builder.Extra
12+
( CommandFields, Mod, Parser, auto, command, help, idm, info
13+
, long, metavar, option, progDesc, showDefault, strOption
14+
, subparser, switch, value
15+
)
16+
import Options.Applicative.Builder.Extra ( boolFlags, textOption )
1317
import Stack.Dot
14-
import Stack.Options.BuildParser
18+
( DotOpts (..), ListDepsFormat (..), ListDepsFormatOpts (..)
19+
, ListDepsOpts (..)
20+
)
21+
import Stack.Options.BuildParser ( flagsParser, targetsParser )
1522
import Stack.Prelude
1623

1724
-- | Parser for arguments to `stack dot`
1825
dotOptsParser :: Bool -> Parser DotOpts
19-
dotOptsParser externalDefault =
20-
DotOpts <$> includeExternal
21-
<*> includeBase
22-
<*> depthLimit
23-
<*> fmap (maybe Set.empty $ Set.fromList . splitNames) prunedPkgs
24-
<*> targetsParser
25-
<*> flagsParser
26-
<*> testTargets
27-
<*> benchTargets
28-
<*> globalHints
29-
where includeExternal = boolFlags externalDefault
30-
"external"
31-
"inclusion of external dependencies"
32-
idm
33-
includeBase = boolFlags True
34-
"include-base"
35-
"inclusion of dependencies on base"
36-
idm
37-
depthLimit =
38-
optional (option auto
39-
(long "depth" <>
40-
metavar "DEPTH" <>
41-
help ("Limit the depth of dependency resolution " <>
42-
"(Default: No limit)")))
43-
prunedPkgs = optional (strOption
44-
(long "prune" <>
45-
metavar "PACKAGES" <>
46-
help ("Prune each package name " <>
47-
"from the comma separated list " <>
48-
"of package names PACKAGES")))
49-
testTargets = switch (long "test" <>
50-
help "Consider dependencies of test components")
51-
benchTargets = switch (long "bench" <>
52-
help "Consider dependencies of benchmark components")
26+
dotOptsParser externalDefault = DotOpts
27+
<$> includeExternal
28+
<*> includeBase
29+
<*> depthLimit
30+
<*> fmap (maybe Set.empty $ Set.fromList . splitNames) prunedPkgs
31+
<*> targetsParser
32+
<*> flagsParser
33+
<*> testTargets
34+
<*> benchTargets
35+
<*> globalHints
36+
where
37+
includeExternal = boolFlags externalDefault
38+
"external"
39+
"inclusion of external dependencies"
40+
idm
41+
includeBase = boolFlags True
42+
"include-base"
43+
"inclusion of dependencies on base"
44+
idm
45+
depthLimit = optional (option auto
46+
( long "depth"
47+
<> metavar "DEPTH"
48+
<> help "Limit the depth of dependency resolution (Default: No limit)"
49+
))
50+
prunedPkgs = optional (strOption
51+
( long "prune"
52+
<> metavar "PACKAGES"
53+
<> help "Prune each package name from the comma separated list of package \
54+
\names PACKAGES"
55+
))
56+
testTargets = switch
57+
( long "test"
58+
<> help "Consider dependencies of test components"
59+
)
60+
benchTargets = switch
61+
( long "bench"
62+
<> help "Consider dependencies of benchmark components"
63+
)
5364

54-
splitNames :: String -> [PackageName]
55-
splitNames = map (mkPackageName . takeWhile (not . isSpace) . dropWhile isSpace) . splitOn ","
65+
splitNames :: String -> [PackageName]
66+
splitNames = map
67+
( mkPackageName
68+
. takeWhile (not . isSpace)
69+
. dropWhile isSpace
70+
) . splitOn ","
5671

57-
globalHints = switch (long "global-hints" <>
58-
help "Do not require an install GHC; instead, use a hints file for global packages")
72+
globalHints = switch
73+
( long "global-hints"
74+
<> help "Do not require an install GHC; instead, use a hints file for \
75+
\global packages"
76+
)
5977

6078
separatorParser :: Parser Text
61-
separatorParser =
62-
fmap escapeSep
63-
(textOption (long "separator" <>
64-
metavar "SEP" <>
65-
help ("Separator between package name " <>
66-
"and package version.") <>
67-
value " " <>
68-
showDefault))
69-
where escapeSep s = T.replace "\\t" "\t" (T.replace "\\n" "\n" s)
79+
separatorParser = fmap
80+
escapeSep
81+
( textOption
82+
( long "separator"
83+
<> metavar "SEP"
84+
<> help "Separator between package name and package version."
85+
<> value " "
86+
<> showDefault
87+
)
88+
)
89+
where
90+
escapeSep s = T.replace "\\t" "\t" (T.replace "\\n" "\n" s)
7091

7192
licenseParser :: Parser Bool
7293
licenseParser = boolFlags False
73-
"license"
74-
"printing of dependency licenses instead of versions"
75-
idm
94+
"license"
95+
"printing of dependency licenses instead of versions"
96+
idm
7697

7798
listDepsFormatOptsParser :: Parser ListDepsFormatOpts
78-
listDepsFormatOptsParser = ListDepsFormatOpts <$> separatorParser <*> licenseParser
99+
listDepsFormatOptsParser = ListDepsFormatOpts
100+
<$> separatorParser
101+
<*> licenseParser
79102

80103
listDepsTreeParser :: Parser ListDepsFormat
81104
listDepsTreeParser = ListDepsTree <$> listDepsFormatOptsParser
@@ -91,23 +114,35 @@ listDepsConstraintsParser = pure ListDepsConstraints
91114

92115
toListDepsOptsParser :: Parser ListDepsFormat -> Parser ListDepsOpts
93116
toListDepsOptsParser formatParser = ListDepsOpts
94-
<$> formatParser
95-
<*> dotOptsParser True
117+
<$> formatParser
118+
<*> dotOptsParser True
96119

97-
formatSubCommand :: String -> String -> Parser ListDepsFormat -> Mod CommandFields ListDepsOpts
120+
formatSubCommand ::
121+
String
122+
-> String
123+
-> Parser ListDepsFormat
124+
-> Mod CommandFields ListDepsOpts
98125
formatSubCommand cmd desc formatParser =
99-
command cmd (info (toListDepsOptsParser formatParser)
100-
(progDesc desc))
126+
command cmd (info (toListDepsOptsParser formatParser) (progDesc desc))
101127

102128
-- | Parser for arguments to `stack ls dependencies`.
103129
listDepsOptsParser :: Parser ListDepsOpts
104130
listDepsOptsParser = subparser
105-
( formatSubCommand
106-
"text" "Print dependencies as text (default)" listDepsTextParser
107-
<> formatSubCommand
108-
"cabal" "Print dependencies as exact Cabal constraints" listDepsConstraintsParser
109-
<> formatSubCommand
110-
"tree" "Print dependencies as tree" listDepsTreeParser
111-
<> formatSubCommand
112-
"json" "Print dependencies as JSON" listDepsJsonParser
113-
) <|> toListDepsOptsParser listDepsTextParser
131+
( formatSubCommand
132+
"text"
133+
"Print dependencies as text (default)"
134+
listDepsTextParser
135+
<> formatSubCommand
136+
"cabal"
137+
"Print dependencies as exact Cabal constraints"
138+
listDepsConstraintsParser
139+
<> formatSubCommand
140+
"tree"
141+
"Print dependencies as tree"
142+
listDepsTreeParser
143+
<> formatSubCommand
144+
"json"
145+
"Print dependencies as JSON"
146+
listDepsJsonParser
147+
)
148+
<|> toListDepsOptsParser listDepsTextParser

0 commit comments

Comments
 (0)