@@ -104,7 +104,8 @@ import Distribution.Simple.Compiler
104
104
, compilerCompatVersion
105
105
)
106
106
import Distribution.Simple.Setup
107
- ( ReplOptions (.. )
107
+ ( Flag
108
+ , ReplOptions (.. )
108
109
, commonSetupTempFileOptions
109
110
)
110
111
import Distribution.Simple.Utils
@@ -296,36 +297,10 @@ replAction flags@NixStyleFlags{extraFlags = replFlags@ReplFlags{..}, configFlags
296
297
baseCtx <- case targetCtx of
297
298
ProjectContext -> do
298
299
let pkgs = projectPackages $ projectConfig ctx
299
- when (null targetSelectors && not (null pkgs)) $
300
- let projectName = case projectConfigProjectFile . projectConfigShared $ projectConfig ctx of
301
- Flag " " -> Nothing
302
- Flag n -> Just $ quotes (text n)
303
- _ -> Nothing
304
- pickComponent = text " pick a single [package:][ctype:]component as target for the REPL command."
305
- msg =
306
- case (null pkgs, projectName) of
307
- (True , Just project) ->
308
- text " There are no packages in"
309
- <+> (project <> char ' .' )
310
- <+> text " Please add a package to the project and"
311
- <+> pickComponent
312
- (True , Nothing ) ->
313
- text " Please add a package to the project and" <+> pickComponent
314
- (False , Just project) ->
315
- text " Please"
316
- <+> pickComponent
317
- <+> text " The packages in"
318
- <+> project
319
- <+> (text " from which to select a component target are" <> colon)
320
- $+$ nest 1 (vcat [text " -" <+> text pkg | pkg <- sort pkgs])
321
- (False , Nothing ) ->
322
- text " Please"
323
- <+> pickComponent
324
- <+> (text " The packages from which to select a component in 'cabal.project'" <> comma)
325
- <+> (text " the implicit default as if `--project-file=cabal.project` was added as a command option" <> comma)
326
- <+> (text " are" <> colon)
327
- $+$ nest 1 (vcat [text " -" <+> text pkg | pkg <- sort pkgs])
328
- in dieWithException verbosity $ RenderReplTargetProblem [render msg]
300
+ when (null targetSelectors && not (null pkgs)) $ do
301
+ let projectFile = projectConfigProjectFile . projectConfigShared $ projectConfig ctx
302
+ dieWithException verbosity $
303
+ RenderReplTargetProblem [render (reportProjectNoTarget projectFile pkgs)]
329
304
return ctx
330
305
GlobalContext -> do
331
306
unless (null targetStrings) $
@@ -560,6 +535,37 @@ replAction flags@NixStyleFlags{extraFlags = replFlags@ReplFlags{..}, configFlags
560
535
, ConstraintSourceMultiRepl
561
536
)
562
537
538
+ reportProjectNoTarget :: Flag FilePath -> [String ] -> Doc
539
+ reportProjectNoTarget projectFile pkgs =
540
+ case (null pkgs, projectName) of
541
+ (True , Just project) ->
542
+ text " There are no packages in"
543
+ <+> (project <> char ' .' )
544
+ <+> text " Please add a package to the project and"
545
+ <+> pickComponent
546
+ (True , Nothing ) ->
547
+ text " Please add a package to the project and" <+> pickComponent
548
+ (False , Just project) ->
549
+ text " Please"
550
+ <+> pickComponent
551
+ <+> text " The packages in"
552
+ <+> project
553
+ <+> (text " from which to select a component target are" <> colon)
554
+ $+$ nest 1 (vcat [text " -" <+> text pkg | pkg <- sort pkgs])
555
+ (False , Nothing ) ->
556
+ text " Please"
557
+ <+> pickComponent
558
+ <+> (text " The packages from which to select a component in 'cabal.project'" <> comma)
559
+ <+> (text " the implicit default as if `--project-file=cabal.project` was added as a command option" <> comma)
560
+ <+> (text " are" <> colon)
561
+ $+$ nest 1 (vcat [text " -" <+> text pkg | pkg <- sort pkgs])
562
+ where
563
+ projectName = case projectFile of
564
+ Flag " " -> Nothing
565
+ Flag n -> Just $ quotes (text n)
566
+ _ -> Nothing
567
+ pickComponent = text " pick a single [package:][ctype:]component as target for the REPL command."
568
+
563
569
validatedTargets
564
570
:: Verbosity
565
571
-> ReplFlags
0 commit comments