Skip to content

Commit b79fa5d

Browse files
committed
Use indentation and highlight style to suggest projection option.
1 parent 760965c commit b79fa5d

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/Stack/Build/Target.hs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,8 @@ parseRawTargetDirs root locals ri =
155155
>>= rejectMissingDir
156156
case mdir of
157157
Nothing -> pure . Left $
158-
if | T.isPrefixOf "stack-yaml" t ->
159-
fillSep
160-
[ flow "Directory not found:"
161-
, style Dir (fromString $ T.unpack t) <> "."
162-
, flow "Is this a typo? Can I suggest:"
163-
, style Dir (fromString $ "--" ++ T.unpack t)
164-
]
165-
| T.isSuffixOf ".yaml" t ->
166-
fillSep
167-
[ flow "Directory not found:"
168-
, style Dir (fromString $ T.unpack t) <> "."
169-
, flow "Is this a typo? Can I suggest:"
170-
, style Dir (fromString $ "--stack-yaml " ++ T.unpack t)
171-
]
158+
if | T.isPrefixOf "stack-yaml=" t -> projectOptionTypo
159+
| T.isSuffixOf ".yaml" t -> projectYamlExtTypo
172160
| otherwise ->
173161
fillSep
174162
[ flow "Directory not found:"
@@ -191,6 +179,22 @@ parseRawTargetDirs root locals ri =
191179

192180
RawInput t = ri
193181

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

0 commit comments

Comments
 (0)