implemented policy editing

This commit is contained in:
Jonathan Lamothe
2018-12-27 15:56:25 -05:00
parent 0920bff2f5
commit 9b5af711b3
2 changed files with 38 additions and 17 deletions

View File

@@ -20,8 +20,9 @@ License along with this program. If not, see
-}
module Util (menu, run, req, tryReq, confirm) where
module Util (menu, run, withService, req, tryReq, confirm) where
import Control.Lens (view)
import Control.Monad (join)
import Control.Monad.Trans.Class (lift)
import qualified Control.Monad.Trans.State as S
@@ -37,6 +38,8 @@ import System.Console.HCL
, runRequest
)
import Password
import Types
menu
@@ -55,6 +58,17 @@ reqState = join . req
run :: Monad m => (s -> (a, s)) -> S.StateT s m a
run f = S.StateT $ return . f
withService
:: String
-> S.StateT Status IO a
-> (PWData -> S.StateT Status IO a)
-> S.StateT Status IO a
withService srv fb act = do
db <- S.gets $ view database
case pwGetService srv db of
Nothing -> fb
Just x -> act x
req :: Request a -> S.StateT s IO a
req = lift . fmap fromJust . runRequest . required