Skip to content

Commit 236d5b8

Browse files
committed
Make reportProjectNoTarget a function
1 parent fa38169 commit 236d5b8

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

cabal-install/src/Distribution/Client/CmdRepl.hs

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ import Distribution.Simple.Compiler
104104
, compilerCompatVersion
105105
)
106106
import Distribution.Simple.Setup
107-
( ReplOptions (..)
107+
( Flag
108+
, ReplOptions (..)
108109
, commonSetupTempFileOptions
109110
)
110111
import Distribution.Simple.Utils
@@ -296,36 +297,10 @@ replAction flags@NixStyleFlags{extraFlags = replFlags@ReplFlags{..}, configFlags
296297
baseCtx <- case targetCtx of
297298
ProjectContext -> do
298299
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)]
329304
return ctx
330305
GlobalContext -> do
331306
unless (null targetStrings) $
@@ -560,6 +535,37 @@ replAction flags@NixStyleFlags{extraFlags = replFlags@ReplFlags{..}, configFlags
560535
, ConstraintSourceMultiRepl
561536
)
562537

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+
563569
validatedTargets
564570
:: Verbosity
565571
-> ReplFlags

0 commit comments

Comments
 (0)