-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli args
- Loading branch information
Showing
9 changed files
with
102 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Jacinda.Include ( defaultIncludes | ||
, resolveImport | ||
) where | ||
|
||
import Control.Exception (Exception, throwIO) | ||
import Control.Monad (filterM) | ||
import Data.List.Split (splitWhen) | ||
import Data.Maybe (listToMaybe) | ||
import Paths_jacinda (getDataDir) | ||
import System.Directory (doesFileExist) | ||
import System.Environment (lookupEnv) | ||
import System.FilePath ((</>)) | ||
|
||
data ImportError = FileNotFound !FilePath ![FilePath] deriving (Show) | ||
|
||
instance Exception ImportError where | ||
|
||
defaultIncludes :: IO ([FilePath] -> [FilePath]) | ||
defaultIncludes = do | ||
path <- jacPath | ||
d <- getDataDir | ||
pure $ (d:) . (++path) | ||
|
||
-- | Parsed @JAC_PATH@ | ||
jacPath :: IO [FilePath] | ||
jacPath = maybe [] splitEnv <$> lookupEnv "JAC_PATH" | ||
|
||
splitEnv :: String -> [FilePath] | ||
splitEnv = splitWhen (== ':') | ||
|
||
resolveImport :: [FilePath] -- ^ Places to look | ||
-> FilePath | ||
-> IO FilePath | ||
resolveImport incl fp = | ||
maybe (throwIO $ FileNotFound fp incl) pure . listToMaybe | ||
=<< (filterM doesFileExist . fmap (</> fp) $ incl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters