aboutsummaryrefslogtreecommitdiff
path: root/app/Main.hs
blob: 0b1f81e0ffd3c578bdae05debb8ad84ea27db83c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Main (main) where

import Control.Arrow (left)
import qualified Cron
import Intro
import System.Environment (getArgs)
import System.IO (getLine)

main :: IO ()
main = do
  cron <- getCron
  putStrLn . showOrErr $ Cron.toProse <$> (Cron.parse =<< cron)

getCron :: IO (Either String String)
getCron = do
  args <- getArgs
  case args of
    [] -> Right <$> getLine
    [x] -> pure $ Right x
    xs -> pure $ Left ("Too many inputs or invalid option: " ++ show xs)

showOrErr :: Either String String -> String
showOrErr = either id id . left ("Error. " ++)