on master help sign in
yaml2json: commandline option '-h'/'--help' and write error to stderr
commit188e851eca9555bd5ffc4da09b662cb3c4299f3e authorMichel Kuhlmann <michel.kuhlmann@tkconsult.ch> dateFri 10 Nov 2017, 13:54 (9 years ago) parent316ccf0
3 files changed+13−4
ChangeLog.md+6 exe/yaml2json.hs+6−3 yaml.cabal+1−1
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+
17## 0.8.24
28
39* 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)
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+
yaml.cabal+1−1
@@ -1,5 +1,5 @@
11name: yaml
2−version: 0.8.24
2+version: 0.8.25
33license: BSD3
44license-file: LICENSE
55author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov