module Hcompta.CLI.Env where import Control.Exception (tryJust) import Control.Monad (Monad(..), guard) import Data.Either (Either(..)) import Prelude (($), (.), IO) import System.Environment as Env (getEnv) import System.IO (FilePath) import System.IO.Error (isDoesNotExistError) import qualified Hcompta.CLI.Context as C import qualified Hcompta.CLI.Lang as Lang import qualified Hcompta.CLI.Write as Write -- | Return 'FilePath's containing 'Hcompta.Format.JCC.Journal's: -- -- * either those given if any, -- * or the one in HCOMPTA_JOURNAL environment variable if any, paths :: C.Context -> [FilePath] -> IO [FilePath] paths c [] = do tryJust (guard . isDoesNotExistError) $ Env.getEnv "HCOMPTA_JOURNAL" >>= \x -> case x of Right ok -> return [ok] Left _ko -> Write.fatal c Lang.Error_No_input_file_given paths _c ps = return ps