]> Git — Sourcephile - comptalang.git/blob - cli/Hcompta/CLI/Env.hs
Add Compta to the symantics.
[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 x <- tryJust (guard . isDoesNotExistError) $
22 Env.getEnv "HCOMPTA_JOURNAL"
23 case x of
24 Right ok -> return [ok]
25 Left _ko -> Write.fatal c Lang.Error_No_input_file_given
26 paths _c ps = return ps