Skip to content

Commit

Permalink
Warning when git package location has fields other than "git" or "com…
Browse files Browse the repository at this point in the history
…mit"
  • Loading branch information
borsboom committed Sep 15, 2015
1 parent ec1c7de commit c0525a2
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}

-- | The Config type.

Expand Down Expand Up @@ -336,7 +338,7 @@ instance ToJSON PackageEntry where
]
instance FromJSON (PackageEntry, [JSONWarning]) where
parseJSON (String t) = do
loc <- parseJSON $ String t
(loc, _::[JSONWarning]) <- parseJSON $ String t
return (PackageEntry
{ peExtraDepMaybe = Nothing
, peValidWanted = Nothing
Expand All @@ -346,7 +348,7 @@ instance FromJSON (PackageEntry, [JSONWarning]) where
parseJSON v = withObjectWarnings "PackageEntry" (\o -> PackageEntry
<$> o ..:? "extra-dep"
<*> o ..:? "valid-wanted"
<*> o ..: "location"
<*> jsonSubWarnings (o ..: "location")
<*> o ..:? "subdirs" ..!= []) v

data PackageLocation
Expand All @@ -361,17 +363,17 @@ instance ToJSON PackageLocation where
toJSON (PLFilePath fp) = toJSON fp
toJSON (PLHttpTarball t) = toJSON t
toJSON (PLGit x y) = toJSON $ T.unwords ["git", x, y]
instance FromJSON PackageLocation where
parseJSON v = git v <|> withText "PackageLocation" (\t -> http t <|> file t) v
instance FromJSON (PackageLocation, [JSONWarning]) where
parseJSON v = git v <|> ((,[]) <$> withText "PackageLocation" (\t -> http t <|> file t) v)
where
file t = pure $ PLFilePath $ T.unpack t
http t =
case parseUrl $ T.unpack t of
Left _ -> mzero
Right _ -> return $ PLHttpTarball t
git = withObject "PackageGitLocation" $ \o -> PLGit
<$> o .: "git"
<*> o .: "commit"
git = withObjectWarnings "PackageGitLocation" $ \o -> PLGit
<$> o ..: "git"
<*> o ..: "commit"

-- | A project is a collection of packages. We can have multiple stack.yaml
-- files, but only one of them may contain project information.
Expand Down

1 comment on commit c0525a2

@borsboom
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ethercrow for the inspiration.

Please sign in to comment.