]> Git — Sourcephile - comptalang.git/blob - cli/Hcompta/CLI/Env.hs
Ajout : Hcompta.Format.JCC.
[comptalang.git] / cli / Hcompta / CLI / Env.hs
1 module Hcompta.CLI.Env where
2
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)
10
11 import qualified Hcompta.CLI.Context as C
12 import qualified Hcompta.CLI.Lang as Lang
13 import qualified Hcompta.CLI.Write as Write
14
15 -- | Return 'FilePath's containing 'Hcompta.Format.JCC.Journal's:
16 --
17 -- * either those given if any,
18 -- * or the one in HCOMPTA_JOURNAL environment variable if any,
19 paths :: C.Context -> [FilePath] -> IO [FilePath]
20 paths c [] = do
21 tryJust (guard . isDoesNotExistError) $ Env.getEnv "HCOMPTA_JOURNAL"
22 >>= \x -> case x of
23 Right ok -> return [ok]
24 Left _ko -> Write.fatal c Lang.Error_No_input_file_given
25 paths _c ps = return ps