Commit 4be03bb3 authored by Paul Ogris's avatar Paul Ogris
Browse files

Support reading from stdin

parent 0ee4b41e
......@@ -12,17 +12,24 @@ import Relax
import Options.Generic
import qualified Data.Text.IO as T
newtype CLI = CLI
{ input :: FilePath <?> "Input file" }
data CLI
= File { input :: FilePath <?> "Input file" }
| Stdin
deriving (Show, Generic)
instance ParseRecord CLI
inputSource :: CLI -> String
inputSource (File f) = unHelpful f
inputSource Stdin = "<stdin>"
main :: IO ()
main = do
cli <- getRecord "lars-relax"
inp <- T.readFile (unHelpful $ input cli)
inp <- case cli of
Stdin -> T.getContents
File{} -> T.readFile (unHelpful $ input cli)
case parse program (unHelpful $ input cli) inp of
case parse program (inputSource cli) inp of
Left e -> error (errorBundlePretty e)
Right x -> T.putStrLn $ prettyProgram (relax x)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment