mirror of
https://github.com/koalaman/shellcheck
synced 2025-08-20 13:23:55 -07:00
Example plumbing for Portage variables
This commit is contained in:
parent
90d3172dfe
commit
0138a6fafc
9 changed files with 96 additions and 59 deletions
|
@ -396,10 +396,12 @@ ioInterface options files = do
|
|||
inputs <- mapM normalize files
|
||||
cache <- newIORef emptyCache
|
||||
configCache <- newIORef ("", Nothing)
|
||||
portageVars <- newIORef Nothing
|
||||
return (newSystemInterface :: SystemInterface IO) {
|
||||
siReadFile = get cache inputs,
|
||||
siFindSource = findSourceFile inputs (sourcePaths options),
|
||||
siGetConfig = getConfig configCache
|
||||
siGetConfig = getConfig configCache,
|
||||
siGetPortageVariables = getOrLoadPortage portageVars
|
||||
}
|
||||
where
|
||||
emptyCache :: Map.Map FilePath String
|
||||
|
@ -523,6 +525,18 @@ ioInterface options files = do
|
|||
("SCRIPTDIR":rest) -> joinPath (scriptdir:rest)
|
||||
_ -> str
|
||||
|
||||
getOrLoadPortage cache = do
|
||||
x <- readIORef cache
|
||||
case x of
|
||||
Just m -> do
|
||||
hPutStrLn stderr "Reusing previous Portage variables"
|
||||
return m
|
||||
Nothing -> do
|
||||
hPutStrLn stderr "Computing Portage variables"
|
||||
vars <- return $ Map.fromList [("foo", ["bar", "baz"])] -- TODO: Actually read the variables
|
||||
writeIORef cache $ Just vars
|
||||
return vars
|
||||
|
||||
inputFile file = do
|
||||
(handle, shouldCache) <-
|
||||
if file == "-"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue