packages feed

moonlight-triangulation-0.1.0.0: fuzz/support/Moonlight/Triangulation/Fuzz/Boundary.hs

{-# LANGUAGE LambdaCase #-}

module Moonlight.Triangulation.Fuzz.Boundary
  ( runFuzzTarget
  ) where

import qualified Data.ByteString as BS
import System.Environment (getArgs)
import System.Exit (die)

runFuzzTarget :: Show failure => (BS.ByteString -> Either failure ()) -> IO ()
runFuzzTarget target =
  readInput >>= either (die . show) (const (pure ())) . target

readInput :: IO BS.ByteString
readInput =
  getArgs >>= \case
    [] -> BS.getContents
    [path] -> BS.readFile path
    _ -> die "expected zero arguments for stdin or one input path"