{-|
Module      : Pulsar.FrontEnd.Options
Description : Common command-line options.
Copyright   : (c) Jesse Haber-Kucharsky, 2014
License     : Apache-2.0
-}

module Pulsar.FrontEnd.Options
  (pathList
  ,outputFile)
  where

import           Data.List.Split     (wordsBy)
import           Options.Applicative

pathList :: Parser [String]
pathList =
  strListOption (long "path"
              <> short 'i'
              <> metavar "PATH[,...]"
              <> help "Search directories in PATHs for files with relative path names.")

outputFile :: Parser String
outputFile =
  strOption (long "output-file"
               <> short 'o'
               <> metavar "FILE"
               <> help "Write output to the named file FILE.")

strListOption :: Mod OptionFields String -> Parser [String]
strListOption flags = toList <$> optional (strOption flags)
 where
   toList :: Maybe String -> [String]
   toList Nothing  = []
   toList (Just s) = wordsBy (== ',') s

