Skip to content

Commit

Permalink
Merge pull request #6033 from cabalism/fix/project-mistaken-for-targe…
Browse files Browse the repository at this point in the history
…t-message

Check if target might be a project-level configuration file, not a missing directory
  • Loading branch information
mpilgrem authored Jan 31, 2023
2 parents 78d2797 + d8561ec commit bc7c17c
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/Stack/Build/Target.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

Expand Down Expand Up @@ -152,11 +153,14 @@ parseRawTargetDirs root locals ri =
Nothing -> do
mdir <- forgivingResolveDir root (T.unpack t) >>= rejectMissingDir
case mdir of
Nothing -> pure $ Left $
fillSep
[ flow "Directory not found:"
, style Dir (fromString $ T.unpack t) <> "."
]
Nothing -> pure . Left $
if | T.isPrefixOf "stack-yaml=" t -> projectOptionTypo
| T.isSuffixOf ".yaml" t -> projectYamlExtTypo
| otherwise ->
fillSep
[ flow "Directory not found:"
, style Dir (fromString $ T.unpack t) <> "."
]
Just dir ->
case mapMaybe (childOf dir) $ Map.toList locals of
[] -> pure $ Left $
Expand All @@ -174,6 +178,22 @@ parseRawTargetDirs root locals ri =

RawInput t = ri

projectOptionTypo :: StyleDoc
projectOptionTypo = let o = "stack-yaml=" in projectTypo 2 (length o) o

projectYamlExtTypo :: StyleDoc
projectYamlExtTypo = let o = "stack-yaml " in projectTypo (2 + length o) 0 o

projectTypo :: Int -> Int -> String -> StyleDoc
projectTypo padLength dropLength option =
vsep
[ style Dir (fromString (replicate padLength ' ') <> fromString (T.unpack t))
<> " is not a directory."
, style Highlight (fromString $ "--" <> option)
<> style Dir (fromString . drop dropLength $ T.unpack t)
<> " might work as a project option."
]

-- | If this function returns @Nothing@, the input should be treated as a
-- directory.
parseRawTarget :: Text -> Maybe RawTarget
Expand Down

0 comments on commit bc7c17c

Please sign in to comment.