1 module Hcompta.CLI.Env where
3 import Control.Exception (tryJust)
4 import Control.Monad (Monad(..), guard)
5 import Data.Either (Either(..))
6 import Prelude (($), (.), IO)
7 import System.Environment as Env (getEnv)
8 import System.IO (FilePath)
9 import System.IO.Error (isDoesNotExistError)
11 import qualified Hcompta.CLI.Context as C
12 import qualified Hcompta.CLI.Lang as Lang
13 import qualified Hcompta.CLI.Write as Write
15 -- | Return 'FilePath's containing 'Hcompta.Format.JCC.Journal's:
17 -- * either those given if any,
18 -- * or the one in HCOMPTA_JOURNAL environment variable if any,
19 paths :: C.Context -> [FilePath] -> IO [FilePath]
21 tryJust (guard . isDoesNotExistError) $ Env.getEnv "HCOMPTA_JOURNAL"
23 Right ok -> return [ok]
24 Left _ko -> Write.fatal c Lang.Error_No_input_file_given
25 paths _c ps = return ps