{- Copyright (C) 2013 John Lenz This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -} module Handler.Raw (getRawCommandR, postRawCommandR) where import Import import qualified Data.Text as T rawForm :: AForm (HandlerT App IO) String rawForm = T.unpack <$> areq textField cmd Nothing where cmd = FieldSettings (SomeMessage MsgRaw) Nothing (Just "Command") Nothing [] getRawCommandR :: Handler Html getRawCommandR = defaultLayout $ do setTitleI MsgRaw ((result,widget),enctype) <- liftHandlerT $ runFormPost $ renderBootstrap rawForm [whamlet|

_{MsgRawWarning}

$case result $of FormFailure reasons $forall r <- reasons
#{r} $of _ ^{widget} |] postRawCommandR :: Handler Html postRawCommandR = do ((result,_),_) <- runFormPost $ renderBootstrap rawForm command <- case result of FormMissing -> invalidArgs ["Form is missing"] FormFailure msg -> invalidArgs msg FormSuccess command -> return command (code,out,err) <- notmuchRaw (words command) defaultLayout $ do setTitleI MsgRaw [whamlet|

#{command}

_{MsgExitCode}: #{show code}

_{MsgStdOut}
  #{out}

_{MsgStdErr}
  #{err}
|]