<commit_before>{-# LANGUAGE ScopedTypeVariables #-}

import Data.Yaml (decodeFileEither, decodeEither')
import System.Environment (getArgs)
import System.Exit
import Data.Aeson (encode, Value)
import Prelude hiding (putStr, getContents)
import Data.ByteString.Lazy (putStr)
import Data.ByteString (getContents)

helpMessage :: IO ()
helpMessage = print "yaml2json FILE\n  use - to indicate stdin" >> exitFailure

showJSON ejson =
    case ejson of
       Left err -> print err >> exitFailure
       Right (res :: Value) -> putStr (encode res) >> exitSuccess

main :: IO ()
main = do
    args <- getArgs
    case args of
       [] -> helpMessage
       (f:a:_)  -> helpMessage
       -- strict getContents will read in all of stdin at once
       ("-":[]) -> getContents >>= showJSON . decodeEither'
       (f:[])   -> decodeFileEither f >>= showJSON
       
<commit_msg>fix newline printing<commit_after>{-# LANGUAGE ScopedTypeVariables #-}

import Data.Yaml (decodeFileEither, decodeEither')
import System.Environment (getArgs)
import System.Exit
import Data.Aeson (encode, Value)
import Prelude hiding (putStr, getContents)
import Data.ByteString.Lazy (putStr)
import Data.ByteString (getContents)

helpMessage :: IO ()
helpMessage = putStrLn "yaml2json FILE\n  use - as FILE to indicate stdin" >> exitFailure

showJSON ejson =
    case ejson of
       Left err -> print err >> exitFailure
       Right (res :: Value) -> putStr (encode res) >> exitSuccess

main :: IO ()
main = do
    args <- getArgs
    case args of
       [] -> helpMessage
       (f:a:_)  -> helpMessage
       -- strict getContents will read in all of stdin at once
       ("-":[]) -> getContents >>= showJSON . decodeEither'
       (f:[])   -> decodeFileEither f >>= showJSON
       

{'fraction_non_alphanumeric': 0.11604095563139932, 'fraction_numerical': 0.0011376564277588168, 'mean_word_length': 3.15839243498818, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '299751', 'n_tokens_mistral': 537, 'n_tokens_neox': 524, 'n_words': 172}