packages feed

hydrogen-cli-0.12: src/H/Common.hs

module H.Common (
    module Hydrogen.Prelude
  , module Hydrogen.CliArgs
  , Tool
  , LogLevel (..)
  , getOpts
  , onFiles
  , (>+>)
  , (<+<)
  ) where

import Hydrogen.Prelude hiding (log)
import Hydrogen.CliArgs hiding (getOpts)
import Hydrogen.Parsing

type Tool = (LogLevel -> String -> IO ()) -> [String] -> IO ()

data LogLevel = WARN | INFO | FINE | FINER | FINEST
  deriving (Eq, Ord, Enum, Show, Read, Generic, Typeable)

onFiles :: (String -> IO ()) -> [String] -> IO ()
onFiles f = \case
    [] -> getContents >>= f
    fs -> mapM_ (readFile >=> f) fs

getOpts :: [String] -> [Option] -> OptArgs
getOpts = flip getOpts'