Skip to content

Commit

Permalink
Use YAML syntax for remote git location identification.
Browse files Browse the repository at this point in the history
As suggested by @greggwebs. The syntax proposed yesterday has the
advantage of concision, but using YAML syntax for the different
components adds marginal verbosity. As it is, the previous syntax made
extensibility problematic, whereas that's exactly where YAML
shines (what if we need an extra field to identify a particular git
commit?). Further, using YAML means people are free to include their own
metadata about package locations, without disturbing Stack.

Here's an example:

- location:
    git: https://github.com/kolmodin/binary
    commit: 8debedd3fcb6525ac0d7de2dd49217dce2abc0d9
  • Loading branch information
mboes committed Jun 10, 2015
1 parent ddce537 commit f10d1f7
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,16 @@ instance ToJSON PackageLocation where
toJSON (PLHttpTarball t) = toJSON t
toJSON (PLGit x y) = toJSON $ T.unwords ["git", x, y]
instance FromJSON PackageLocation where
parseJSON = withText "PackageLocation" $ \t ->
http t <|> git t <|> pure (PLFilePath $ T.unpack t)
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 t =
case T.words t of
["git", x, y] -> return $ PLGit x y
_ -> mzero
git = withObject "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

0 comments on commit f10d1f7

Please sign in to comment.