definition:
|
askCurryInfoCmd :: Bool -> Int -> String -> CurryEntity -> String
-> IO (Maybe [(QName, String)])
askCurryInfoCmd remote verb modname entkind req
| entkind == Unknown = return Nothing
| otherwise = do
mres <- getPackageVersionOfModule modname
case mres of
Nothing -> return Nothing
Just (pkg, vsn) -> do
-- Note: force=0 is important to avoid loops if the analysis tools
-- also use `curry-info`!
-- Verbosity 0/quiet is also important, otherwise buffer for stderr
-- will be filled in the `evalCmd` call so that it might overflow.
let queryopts = defaultOptions
{ optForce = 0, optVerb = 0, optAll = True
, optRemote = remote, optRemoteURL = curryInfoURL
, optOutFormat = "CurryTerm"
, optPackage = pkg, optVersion = vsn
, optModule = modname
, optRequest = [req] }
(cmd,cmdopts) = curryInfoCmd queryopts (curryInfoOptions queryopts)
when (verb > 1) $ hPutStrLn stderr $
unwords $ ["Executing:", cmd] ++ cmdopts
(ec, out, err) <- evalCmd cmd cmdopts ""
if ec > 0
then do when (verb > 0) $ do
hPutStrLn stderr $ line ++ "Execution error. Output:"
unless (null out) $ hPutStrLn stderr out
unless (null err) $ hPutStrLn stderr err
hPutStrLn stderr line
return Nothing
else do
let mbres = do results <- (safeRead out :: Maybe [(String, String)])
mapM readResult results
maybe (readError out) (return . Just) mbres
where
line = take 70 (repeat '-') ++ "\n"
readError s = do
when (verb > 0) $ hPutStrLn stderr $
line ++ "Error reading output:\n" ++ s ++ line
return Nothing
readResult :: (String, String) -> Maybe (QName, String)
readResult (obj, res) = do
(m, o) <- (safeRead obj :: Maybe (String, String))
[(_, result)] <- (safeRead res :: Maybe [(String, String)])
return ((m, o), result)
|
documentation:
|
------------------------------------------------------------------------------
--- This action uses the `curry-info` command to return the result
--- of the given request (third argument) for all entities in the module
--- provided as the third argument. The requested result is returned in its
--- string representation for each entity in the module.
--- If the first argument is `True`, the `curry-info` web service is queried.
--- The second is the verbosity (where 0 means quiet).
--- The fourth argument is the kind of entity to be queried.
--- If it is `Unknown`, `Nothing` is returned.
---
--- The package and version are determined using the Curry loadpath.
--- If something goes wrong, Nothing is returned.
---
--- Example: get the demanded arguments of all operations in module `Data.List`:
---
--- > askCurryInfoCmd True 1 "Data.List" Operation "demand"
---
|