on master help sign in
Merge pull request #119 from michelk/yaml2json-help
cff8c83Michael Snoyman
ChangeLog.md+6
@@ -1,3 +1,9 @@
1+## 0.8.25
2+
3+* Tweaks to the executable `yaml2json` [#119](https://github.com/snoyberg/yaml/pull/119):
4+ - Add command-line option `-h` and `--help` to show help message
5+ - Error messages are now written to `stderr` instead of `stdout`
6+
1## 0.8.24
7## 0.8.24
2
8
3* New encodePretty option `setConfDropNull` to drop null values from objects [#116](https://github.com/snoyberg/yaml/issues/116)
9* New encodePretty option `setConfDropNull` to drop null values from objects [#116](https://github.com/snoyberg/yaml/issues/116)
exe/yaml2json.hs+6−3
@@ -5,16 +5,17 @@ import Data.ByteString (getContents)
5import Data.ByteString.Lazy (putStr)
5import Data.ByteString.Lazy (putStr)
6import System.Environment (getArgs)
6import System.Environment (getArgs)
7import System.Exit
7import System.Exit
8+import System.IO (stderr, hPutStrLn)
8
9
9import Data.Yaml (decodeFileEither, decodeEither')
10import Data.Yaml (decodeFileEither, decodeEither')
10
11
11helpMessage :: IO ()
12helpMessage :: 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
13
14
14showJSON :: Show a => Either a Value -> IO b
15showJSON :: Show a => Either a Value -> IO b
15showJSON ejson =
16showJSON ejson =
16 case ejson of
17 case ejson of
17− Left err -> print err >> exitFailure
18+ Left err -> hPutStrLn stderr (show err) >> exitFailure
18 Right res -> putStr (encode (res :: Value)) >> exitSuccess
19 Right res -> putStr (encode (res :: Value)) >> exitSuccess
19
20
20main :: IO ()
21main :: IO ()
@@ -22,7 +23,9 @@ main = do
22 args <- getArgs
23 args <- getArgs
23 case args of
24 case args of
24 -- strict getContents will read in all of stdin at once
25 -- strict getContents will read in all of stdin at once
26+ (["-h"]) -> helpMessage
27+ (["--help"]) -> helpMessage
25 (["-"]) -> getContents >>= showJSON . decodeEither'
28 (["-"]) -> getContents >>= showJSON . decodeEither'
26 ([f]) -> decodeFileEither f >>= showJSON
29 ([f]) -> decodeFileEither f >>= showJSON
27 _ -> helpMessage
30 _ -> helpMessage
28−
31+
yaml.cabal+1−1
@@ -1,5 +1,5 @@
1name: yaml
1name: yaml
2−version: 0.8.24
2+version: 0.8.25
3license: BSD3
3license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov