@@ -13,12 +13,8 @@ Make changes to project or global configuration.
13
13
-}
14
14
15
15
module Stack.ConfigCmd
16
- ( ConfigCmdSet (.. )
17
- , CommandScope
18
- , configCmdSetParser
19
- , cfgCmdSet
16
+ ( cfgCmdSet
20
17
, cfgCmdSetName
21
- , configCmdEnvParser
22
18
, cfgCmdEnv
23
19
, cfgCmdEnvName
24
20
, cfgCmdBuildFiles
@@ -35,9 +31,6 @@ import Data.Attoparsec.Text as P
35
31
import qualified Data.Map.Merge.Strict as Map
36
32
import qualified Data.Text as T
37
33
import qualified Data.Yaml as Yaml
38
- import qualified Options.Applicative as OA
39
- import Options.Applicative.Builder.Extra
40
- import qualified Options.Applicative.Types as OA
41
34
import Pantry ( loadSnapshot )
42
35
import Path ( (</>) , parent )
43
36
import qualified RIO.Map as Map
@@ -58,13 +51,15 @@ import Stack.Types.ConfigMonoid
58
51
, configMonoidRecommendStackUpgradeName
59
52
, configMonoidSystemGHCName
60
53
)
54
+ import Stack.Types.ConfigSetOpts
55
+ ( CommandScope (.. ), ConfigCmdSet (.. ) ,configCmdSetScope )
61
56
import Stack.Types.EnvConfig ( EnvConfig )
62
57
import Stack.Types.EnvSettings ( EnvSettings (.. ) )
63
58
import Stack.Types.GHCVariant ( HasGHCVariant )
64
59
import Stack.Types.GlobalOpts ( GlobalOpts (.. ) )
65
60
import Stack.Types.ProjectConfig ( ProjectConfig (.. ) )
66
61
import Stack.Types.Runner ( globalOptsL )
67
- import Stack.Types.Snapshot ( AbstractSnapshot , readAbstractSnapshot )
62
+ import Stack.Types.Snapshot ( AbstractSnapshot )
68
63
import System.Environment ( getEnvironment )
69
64
70
65
-- | Type repesenting exceptions thrown by functions exported by the
@@ -78,31 +73,7 @@ instance Exception ConfigCmdException where
78
73
" Error: [S-3136]\n "
79
74
++ " 'config' command used when no project configuration available."
80
75
81
- data ConfigCmdSet
82
- = ConfigCmdSetSnapshot ! (Unresolved AbstractSnapshot )
83
- | ConfigCmdSetResolver ! (Unresolved AbstractSnapshot )
84
- | ConfigCmdSetSystemGhc ! CommandScope ! Bool
85
- | ConfigCmdSetInstallGhc ! CommandScope ! Bool
86
- | ConfigCmdSetInstallMsys ! CommandScope ! Bool
87
- | ConfigCmdSetRecommendStackUpgrade ! CommandScope ! Bool
88
- | ConfigCmdSetDownloadPrefix ! CommandScope ! Text
89
-
90
- data CommandScope
91
- = CommandScopeGlobal
92
- -- ^ Apply changes to the global configuration,
93
- -- typically at @~/.stack/config.yaml@.
94
- | CommandScopeProject
95
- -- ^ Apply changes to the project @stack.yaml@.
96
-
97
- configCmdSetScope :: ConfigCmdSet -> CommandScope
98
- configCmdSetScope (ConfigCmdSetSnapshot _) = CommandScopeProject
99
- configCmdSetScope (ConfigCmdSetResolver _) = CommandScopeProject
100
- configCmdSetScope (ConfigCmdSetSystemGhc scope _) = scope
101
- configCmdSetScope (ConfigCmdSetInstallGhc scope _) = scope
102
- configCmdSetScope (ConfigCmdSetInstallMsys scope _) = scope
103
- configCmdSetScope (ConfigCmdSetRecommendStackUpgrade scope _) = scope
104
- configCmdSetScope (ConfigCmdSetDownloadPrefix scope _) = scope
105
-
76
+ -- | Function underlying Stack's @config set@ command.
106
77
cfgCmdSet ::
107
78
(HasConfig env , HasGHCVariant env )
108
79
=> ConfigCmdSet -> RIO env ()
@@ -309,148 +280,26 @@ cfgCmdSetKeys (ConfigCmdSetRecommendStackUpgrade _ _) =
309
280
cfgCmdSetKeys (ConfigCmdSetDownloadPrefix _ _) =
310
281
[[" package-index" , " download-prefix" ]]
311
282
283
+ -- | The name of Stack's @config@ command.
312
284
cfgCmdName :: String
313
285
cfgCmdName = " config"
314
286
287
+ -- | The name of Stack's @config@ command's @set@ subcommand.
315
288
cfgCmdSetName :: String
316
289
cfgCmdSetName = " set"
317
290
291
+ -- | The name of Stack's @config@ command's @env@ subcommand.
318
292
cfgCmdEnvName :: String
319
293
cfgCmdEnvName = " env"
320
294
295
+ -- | The name of Stack's @config@ command's @build-files@ subcommand.
321
296
cfgCmdBuildFilesName :: String
322
297
cfgCmdBuildFilesName = " build-files"
323
298
324
- configCmdSetParser :: OA. Parser ConfigCmdSet
325
- configCmdSetParser =
326
- OA. hsubparser $
327
- mconcat
328
- [ OA. command " snapshot"
329
- ( OA. info
330
- ( ConfigCmdSetSnapshot
331
- <$> OA. argument
332
- readAbstractSnapshot
333
- ( OA. metavar " SNAPSHOT"
334
- <> OA. help " E.g. \" nightly\" or \" lts-22.8\" " ))
335
- ( OA. progDesc
336
- " Change the snapshot of the current project." ))
337
- , OA. command " resolver"
338
- ( OA. info
339
- ( ConfigCmdSetResolver
340
- <$> OA. argument
341
- readAbstractSnapshot
342
- ( OA. metavar " SNAPSHOT"
343
- <> OA. help " E.g. \" nightly\" or \" lts-22.8\" " ))
344
- ( OA. progDesc
345
- " Change the snapshot of the current project, using the \
346
- \resolver key." ))
347
- , OA. command (T. unpack configMonoidSystemGHCName)
348
- ( OA. info
349
- ( ConfigCmdSetSystemGhc
350
- <$> globalScopeFlag
351
- <*> boolArgument )
352
- ( OA. progDesc
353
- " Configure whether or not Stack should use a system GHC \
354
- \installation." ))
355
- , OA. command (T. unpack configMonoidInstallGHCName)
356
- ( OA. info
357
- ( ConfigCmdSetInstallGhc
358
- <$> globalScopeFlag
359
- <*> boolArgument )
360
- ( OA. progDesc
361
- " Configure whether or not Stack should automatically install \
362
- \GHC when necessary." ))
363
- , OA. command (T. unpack configMonoidInstallMsysName)
364
- ( OA. info
365
- ( ConfigCmdSetInstallMsys
366
- <$> globalScopeFlag
367
- <*> boolArgument )
368
- ( OA. progDesc
369
- " Configure whether or not Stack should automatically install \
370
- \MSYS2 when necessary." ))
371
- , OA. command (T. unpack configMonoidRecommendStackUpgradeName)
372
- ( OA. info
373
- ( ConfigCmdSetRecommendStackUpgrade
374
- <$> projectScopeFlag
375
- <*> boolArgument )
376
- ( OA. progDesc
377
- " Configure whether or not Stack should notify the user if it \
378
- \identifes a new version of Stack is available." ))
379
- , OA. command " package-index"
380
- ( OA. info
381
- ( OA. hsubparser $
382
- OA. command " download-prefix"
383
- ( OA. info
384
- ( ConfigCmdSetDownloadPrefix
385
- <$> globalScopeFlag
386
- <*> urlArgument )
387
- ( OA. progDesc
388
- " Configure download prefix for Stack's package \
389
- \index." )))
390
- ( OA. progDesc
391
- " Configure Stack's package index" ))
392
- ]
393
-
394
- globalScopeFlag :: OA. Parser CommandScope
395
- globalScopeFlag = OA. flag
396
- CommandScopeProject
397
- CommandScopeGlobal
398
- ( OA. long " global"
399
- <> OA. help
400
- " Modify the user-specific global configuration file ('config.yaml') \
401
- \instead of the project-level configuration file ('stack.yaml')."
402
- )
403
-
404
- projectScopeFlag :: OA. Parser CommandScope
405
- projectScopeFlag = OA. flag
406
- CommandScopeGlobal
407
- CommandScopeProject
408
- ( OA. long " project"
409
- <> OA. help
410
- " Modify the project-level configuration file ('stack.yaml') instead of \
411
- \the user-specific global configuration file ('config.yaml')."
412
- )
413
-
414
- readBool :: OA. ReadM Bool
415
- readBool = do
416
- s <- OA. readerAsk
417
- case s of
418
- " true" -> pure True
419
- " false" -> pure False
420
- _ -> OA. readerError (" Invalid value " ++ show s ++
421
- " : Expected \" true\" or \" false\" " )
422
-
423
- boolArgument :: OA. Parser Bool
424
- boolArgument = OA. argument
425
- readBool
426
- ( OA. metavar " true|false"
427
- <> OA. completeWith [" true" , " false" ]
428
- )
429
-
430
- urlArgument :: OA. Parser Text
431
- urlArgument = OA. strArgument
432
- ( OA. metavar " URL"
433
- <> OA. value defaultDownloadPrefix
434
- <> OA. showDefault
435
- <> OA. help
436
- " Location of package index. It is highly recommended to use only the \
437
- \official Hackage server or a mirror."
438
- )
439
-
440
- configCmdEnvParser :: OA. Parser EnvSettings
441
- configCmdEnvParser = EnvSettings
442
- <$> boolFlags True " locals" " include information about local packages" mempty
443
- <*> boolFlags True
444
- " ghc-package-path" " set GHC_PACKAGE_PATH environment variable" mempty
445
- <*> boolFlags True " stack-exe" " set STACK_EXE environment variable" mempty
446
- <*> boolFlags False
447
- " locale-utf8" " set the GHC_CHARENC environment variable to UTF-8" mempty
448
- <*> boolFlags False
449
- " keep-ghc-rts" " keep any GHCRTS environment variable" mempty
450
-
451
299
data EnvVarAction = EVASet ! Text | EVAUnset
452
300
deriving Show
453
301
302
+ -- | Function underlying Stack's @config env@ command.
454
303
cfgCmdEnv :: EnvSettings -> RIO EnvConfig ()
455
304
cfgCmdEnv es = do
456
305
origEnv <- liftIO $ Map. fromList . map (first fromString) <$> getEnvironment
0 commit comments