@@ -9,73 +9,96 @@ import qualified Data.Set as Set
99import qualified Data.Text as T
1010import Distribution.Types.PackageName ( mkPackageName )
1111import 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 )
1317import Stack.Dot
14- import Stack.Options.BuildParser
18+ ( DotOpts (.. ), ListDepsFormat (.. ), ListDepsFormatOpts (.. )
19+ , ListDepsOpts (.. )
20+ )
21+ import Stack.Options.BuildParser ( flagsParser , targetsParser )
1522import Stack.Prelude
1623
1724-- | Parser for arguments to `stack dot`
1825dotOptsParser :: 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
6078separatorParser :: 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
7192licenseParser :: Parser Bool
7293licenseParser = 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
7798listDepsFormatOptsParser :: Parser ListDepsFormatOpts
78- listDepsFormatOptsParser = ListDepsFormatOpts <$> separatorParser <*> licenseParser
99+ listDepsFormatOptsParser = ListDepsFormatOpts
100+ <$> separatorParser
101+ <*> licenseParser
79102
80103listDepsTreeParser :: Parser ListDepsFormat
81104listDepsTreeParser = ListDepsTree <$> listDepsFormatOptsParser
@@ -91,23 +114,35 @@ listDepsConstraintsParser = pure ListDepsConstraints
91114
92115toListDepsOptsParser :: Parser ListDepsFormat -> Parser ListDepsOpts
93116toListDepsOptsParser 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
98125formatSubCommand 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`.
103129listDepsOptsParser :: Parser ListDepsOpts
104130listDepsOptsParser = 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