@@ -5,16 +5,17 @@ import Data.ByteString (getContents)
55import Data.ByteString.Lazy (putStr)
66import System.Environment (getArgs)
77import System.Exit
8+import System.IO (stderr, hPutStrLn)
89
910import Data.Yaml (decodeFileEither, decodeEither')
1011
1112helpMessage :: IO ()
12−helpMessage = putStrLn "yaml2json FILE\n use - as FILE to indicate stdin" >> exitFailure
13+helpMessage = putStrLn "Usage: yaml2json FILE\n\nuse '-' as FILE to indicate stdin" >> exitFailure
1314
1415showJSON :: Show a => Either a Value -> IO b
1516showJSON ejson =
1617 case ejson of
17− Left err -> print err >> exitFailure
18+ Left err -> hPutStrLn stderr (show err) >> exitFailure
1819 Right res -> putStr (encode (res :: Value)) >> exitSuccess
1920
2021main :: IO ()
@@ -22,7 +23,9 @@ main = do
2223 args <- getArgs
2324 case args of
2425 -- strict getContents will read in all of stdin at once
26+ (["-h"]) -> helpMessage
27+ (["--help"]) -> helpMessage
2528 (["-"]) -> getContents >>= showJSON . decodeEither'
2629 ([f]) -> decodeFileEither f >>= showJSON
2730 _ -> helpMessage
28−
31+