@@ -0,0 +1,28 @@
1+{-# LANGUAGE ScopedTypeVariables #-}
2+
3+import Data.Yaml (decodeFileEither, decodeEither')
4+import System.Environment (getArgs)
5+import System.Exit
6+import Data.Aeson (encode, Value)
7+import Prelude hiding (putStr, getContents)
8+import Data.ByteString.Lazy (putStr)
9+import Data.ByteString (getContents)
10+
11+helpMessage :: IO ()
12+helpMessage = putStrLn "yaml2json FILE\n use - as FILE to indicate stdin" >> exitFailure
13+
14+showJSON ejson =
15+ case ejson of
16+ Left err -> print err >> exitFailure
17+ Right (res :: Value) -> putStr (encode res) >> exitSuccess
18+
19+main :: IO ()
20+main = do
21+ args <- getArgs
22+ case args of
23+ [] -> helpMessage
24+ (f:a:_) -> helpMessage
25+ -- strict getContents will read in all of stdin at once
26+ ("-":[]) -> getContents >>= showJSON . decodeEither'
27+ (f:[]) -> decodeFileEither f >>= showJSON
28+