json-tools 0.2.1 → 0.2.2
raw patch · 2 files changed
+22/−9 lines, 2 files
Files
- json-tools.cabal +1/−1
- json-unlines.hs +21/−8
json-tools.cabal view
@@ -1,6 +1,6 @@ Name: json-tools Cabal-Version: >=1.6-Version: 0.2.1+Version: 0.2.2 License: BSD3 License-File: LICENSE Copyright: (c) Nicolas Pouillard
json-unlines.hs view
@@ -1,18 +1,31 @@ {-# LANGUAGE OverloadedStrings #-} import qualified Data.ByteString.Char8 as L-import System.Environment+import Control.Monad (when)+import System.Environment (getArgs)+import System.Exit (exitFailure)+import System.IO (hPutStrLn,stderr) -- utility function-getAllContents :: IO L.ByteString-getAllContents =- do args <- getArgs- if null args- then L.getContents- else fmap L.concat . mapM file $ args+getAllContents :: [String] -> IO L.ByteString+getAllContents args+ | null args = L.getContents+ | otherwise = fmap L.concat . mapM file $ args where file "-" = L.getContents file xs = L.readFile xs +usage :: IO a+usage = mapM_ (hPutStrLn stderr)+ ["Usage: json-unline [--help] <file>*"+ ,""+ ,"Reads the given files line by line (or standard input, if '-' or"+ ,"no file is given). Writes on standard output the a JSON array"+ ,"made of the JSON document found on each line."]+ >> exitFailure+ main :: IO () main = do- L.putStrLn . L.cons '[' . L.intercalate "\n," . L.lines =<< getAllContents+ args <- getArgs+ when ("--help"`elem`args) usage+ L.putStrLn . L.cons '[' . L.intercalate "\n," . L.lines+ =<< getAllContents args L.putStrLn "]"