on master help sign in
Merge pull request #30 from gregwebs/yaml2json
5b79457Michael Snoyman
.gitignore+2
@@ -3,3 +3,5 @@ dist
3tmp.yaml
3tmp.yaml
4tmp2.yaml
4tmp2.yaml
5cabal-dev/
5cabal-dev/
6+.cabal-sandbox/
7+cabal.sandbox.config
exe/yaml2json.hsnew file+28
@@ -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+
yaml.cabal+18
@@ -29,6 +29,10 @@ extra-source-files: c/helper.h,
29 test/largest-string.yaml
29 test/largest-string.yaml
30 test/json.yaml
30 test/json.yaml
31
31
32+flag no-exe
33+ description: don't install the yaml2json executable
34+ default: False
35+
32flag system-libyaml
36flag system-libyaml
33 description: Use the system-wide libyaml instead of the bundled copy
37 description: Use the system-wide libyaml instead of the bundled copy
34 default: False
38 default: False
@@ -63,6 +67,20 @@ library
63 libyaml/writer.c
67 libyaml/writer.c
64 include-dirs: libyaml
68 include-dirs: libyaml
65
69
70+executable yaml2json
71+ if flag(no-exe)
72+ Buildable: False
73+ else
74+ Buildable: True
75+
76+ hs-source-dirs: exe
77+ main-is: yaml2json.hs
78+ build-depends: base >= 4 && < 5
79+ , yaml
80+ , bytestring >= 0.9.1.4
81+ , aeson >= 0.5
82+
83+
66test-suite test
84test-suite test
67 type: exitcode-stdio-1.0
85 type: exitcode-stdio-1.0
68 hs-source-dirs: test
86 hs-source-dirs: test