Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #55 from rayqiu/master

Update yaml2json.hs
  • Loading branch information...
commit a9f4c7185dcd6045df6d758adccf44e444931d71 2 parents 96d77a7 + 85c2339
Michael Snoyman authored
Showing with 5 additions and 7 deletions.
  1. +5 −7 exe/yaml2json.hs
12 exe/yaml2json.hs
View
@@ -1,5 +1,3 @@
-{-# LANGUAGE ScopedTypeVariables #-}
-
import Data.Yaml (decodeFileEither, decodeEither')
import System.Environment (getArgs)
import System.Exit
@@ -11,18 +9,18 @@ import Data.ByteString (getContents)
helpMessage :: IO ()
helpMessage = putStrLn "yaml2json FILE\n use - as FILE to indicate stdin" >> exitFailure
+showJSON :: Show a => Either a Value -> IO b
showJSON ejson =
case ejson of
Left err -> print err >> exitFailure
- Right (res :: Value) -> putStr (encode res) >> exitSuccess
+ Right res -> putStr (encode (res :: Value)) >> exitSuccess
main :: IO ()
main = do
args <- getArgs
case args of
- [] -> helpMessage
- (f:a:_) -> helpMessage
-- strict getContents will read in all of stdin at once
- ("-":[]) -> getContents >>= showJSON . decodeEither'
- (f:[]) -> decodeFileEither f >>= showJSON
+ (["-"]) -> getContents >>= showJSON . decodeEither'
+ ([f]) -> decodeFileEither f >>= showJSON
+ _ -> helpMessage
Please sign in to comment.
Something went wrong with that request. Please try again.