Skip to content

Commit bc7c17c

Browse files
authored
Merge pull request #6033 from cabalism/fix/project-mistaken-for-target-message
Check if target might be a project-level configuration file, not a missing directory
2 parents 78d2797 + d8561ec commit bc7c17c

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/Stack/Build/Target.hs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
22
{-# LANGUAGE DataKinds #-}
33
{-# LANGUAGE GADTs #-}
4+
{-# LANGUAGE MultiWayIf #-}
45
{-# LANGUAGE OverloadedStrings #-}
56
{-# LANGUAGE ViewPatterns #-}
67

@@ -152,11 +153,14 @@ parseRawTargetDirs root locals ri =
152153
Nothing -> do
153154
mdir <- forgivingResolveDir root (T.unpack t) >>= rejectMissingDir
154155
case mdir of
155-
Nothing -> pure $ Left $
156-
fillSep
157-
[ flow "Directory not found:"
158-
, style Dir (fromString $ T.unpack t) <> "."
159-
]
156+
Nothing -> pure . Left $
157+
if | T.isPrefixOf "stack-yaml=" t -> projectOptionTypo
158+
| T.isSuffixOf ".yaml" t -> projectYamlExtTypo
159+
| otherwise ->
160+
fillSep
161+
[ flow "Directory not found:"
162+
, style Dir (fromString $ T.unpack t) <> "."
163+
]
160164
Just dir ->
161165
case mapMaybe (childOf dir) $ Map.toList locals of
162166
[] -> pure $ Left $
@@ -174,6 +178,22 @@ parseRawTargetDirs root locals ri =
174178

175179
RawInput t = ri
176180

181+
projectOptionTypo :: StyleDoc
182+
projectOptionTypo = let o = "stack-yaml=" in projectTypo 2 (length o) o
183+
184+
projectYamlExtTypo :: StyleDoc
185+
projectYamlExtTypo = let o = "stack-yaml " in projectTypo (2 + length o) 0 o
186+
187+
projectTypo :: Int -> Int -> String -> StyleDoc
188+
projectTypo padLength dropLength option =
189+
vsep
190+
[ style Dir (fromString (replicate padLength ' ') <> fromString (T.unpack t))
191+
<> " is not a directory."
192+
, style Highlight (fromString $ "--" <> option)
193+
<> style Dir (fromString . drop dropLength $ T.unpack t)
194+
<> " might work as a project option."
195+
]
196+
177197
-- | If this function returns @Nothing@, the input should be treated as a
178198
-- directory.
179199
parseRawTarget :: Text -> Maybe RawTarget

0 commit comments

Comments
 (0)