Skip to content

Commit

Permalink
Merge pull request #503 from bgamari/master
Browse files Browse the repository at this point in the history
Implement getShakeExtra
  • Loading branch information
ndmitchell authored Dec 20, 2016
2 parents c254df4 + d7854ee commit f2406e7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Development/Shake/Internal/Core/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module Development.Shake.Internal.Core.Action(
runAction, actionOnException, actionFinally,
getShakeOptions, getProgress, runAfter,
getShakeOptions, getShakeExtra, getProgress, runAfter,
trackUse, trackChange, trackAllow, trackCheckUsed,
getVerbosity, putWhen, putLoud, putNormal, putQuiet, withVerbosity, quietly,
blockApply, unsafeAllowApply,
Expand All @@ -16,11 +16,13 @@ import Control.Monad.Extra
import Control.Monad.IO.Class
import Control.DeepSeq
import Data.Typeable.Extra
import Data.Dynamic (fromDynamic, dynTypeRep)
import Data.Function
import Data.Either.Extra
import Data.Maybe
import Data.IORef
import Data.List
import qualified Data.HashMap.Strict as Map
import System.IO.Extra

import Development.Shake.Internal.Core.Database
Expand Down Expand Up @@ -67,6 +69,21 @@ actionFinally = actionBoom True
getShakeOptions :: Action ShakeOptions
getShakeOptions = Action $ getsRO globalOptions

-- | Get an item from 'shakeExtras', using the requested type as the key. Fails
-- if the value found at this key does not match the requested type.
getShakeExtra :: forall a. Typeable a => Action (Maybe a)
getShakeExtra = do
mx <- Map.lookup rep . shakeExtra <$> getShakeOptions
case mx of
Just dyn
| Just x <- fromDynamic dyn -> return $ Just x
| otherwise ->
let err = "getShakeExtra: Key "++show rep++" had value of unexpected type "++show (dynTypeRep dyn)
in fail err
Nothing -> return Nothing
where
rep = typeRep (Proxy :: Proxy a)

-- | Get the current 'Progress' structure, as would be returned by 'shakeProgress'.
getProgress :: Action Progress
getProgress = do
Expand Down

0 comments on commit f2406e7

Please sign in to comment.