on master help sign in
create a basic yaml2json executable
commiteba160c6800fa30ddf6b4e12c729ad6ee169ed5c authorGreg Weber <greg@gregweber.info> dateWed 4 Sep 2013, 10:43 (13 years ago) parentd8bd9eb
2 files changed+36
exe/yaml2json.hs+18 yaml.cabal+18
exe/yaml2json.hsnew file+18
@@ -0,0 +1,18 @@
1+{-# LANGUAGE ScopedTypeVariables #-}
2+import Data.Yaml (decodeFileEither)
3+import System.Environment (getArgs)
4+import System.Exit
5+import Data.Aeson (encode, Value)
6+import Prelude hiding (putStr)
7+import Data.ByteString.Lazy (putStr)
8+
9+main = do
10+ args <- getArgs
11+ case args of
12+ [] -> print "yaml2json FILE" >> exitFailure
13+ (f:args) -> do
14+ ejson <- decodeFileEither f
15+ case ejson of
16+ Left err -> print err >> exitFailure
17+ Right (res :: Value) -> putStr (encode res) >> exitSuccess
18+
yaml.cabal+18
@@ -29,6 +29,10 @@ extra-source-files: c/helper.h,
2929 test/largest-string.yaml
3030 test/json.yaml
3131
32+flag no-exe
33+ description: don't install the yaml2json executable
34+ default: False
35+
3236flag system-libyaml
3337 description: Use the system-wide libyaml instead of the bundled copy
3438 default: False
@@ -63,6 +67,20 @@ library
6367 libyaml/writer.c
6468 include-dirs: libyaml
6569
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+
6684test-suite test
6785 type: exitcode-stdio-1.0
6886 hs-source-dirs: test