{-# LANGUAGE OverloadedStrings #-}

module Bricoleur
( main
, Opt.getOpts
) where

import qualified System.Exit as Sys

import qualified Bricoleur.Config as Conf
import qualified Bricoleur.Opts as Opt

import qualified Bricoleur.Commands.Splice as Cmd
import qualified Bricoleur.Commands.Test as Cmd

-- | Run the main @bricoleur@ function with the provided options.
main :: Opt.Options -> IO ()
main opts = do
  configMb <- Conf.getConfig (Opt.optFile opts)
  config <- case configMb of
    Left err -> Sys.die err
    Right x -> return x
  case Opt.optCommand opts of
    Opt.Test   -> Cmd.runTest config opts
    Opt.Splice -> Cmd.runSplice config opts
