mirror of https://github.com/voidlizard/hbs2
wip
This commit is contained in:
parent
995710fce2
commit
b91f0323e6
|
@ -12,6 +12,7 @@ import Data.Function
|
|||
import Data.Text.Encoding.Error qualified as TE
|
||||
import Data.Text.Encoding qualified as TE
|
||||
import Data.Text qualified as T
|
||||
import Data.Text (Text)
|
||||
import Data.Typeable
|
||||
import Prettyprinter
|
||||
import System.Process.Typed
|
||||
|
@ -49,3 +50,25 @@ callProc name params syn = do
|
|||
parseTop s & either (liftIO . throwIO) pure
|
||||
|
||||
|
||||
pipeProcText :: forall m . MonadIO m
|
||||
=> FilePath
|
||||
-> [String]
|
||||
-> Text
|
||||
-> m Text
|
||||
|
||||
pipeProcText name params input' = do
|
||||
|
||||
let input = LBS.fromStrict (TE.encodeUtf8 input')
|
||||
& byteStringInput
|
||||
|
||||
|
||||
let what = proc name params & setStderr closed & setStdin input
|
||||
(code, i, o) <- readProcess what
|
||||
|
||||
unless (code == ExitSuccess) do
|
||||
liftIO $ hPrint stderr ( pretty $ LBS8.unpack o )
|
||||
liftIO $ throwIO (CallProcException code)
|
||||
|
||||
pure $ TE.decodeUtf8With TE.lenientDecode (LBS.toStrict i)
|
||||
|
||||
|
||||
|
|
|
@ -1633,6 +1633,16 @@ internalEntries = do
|
|||
|
||||
_ -> throwIO (BadFormException @c nil)
|
||||
|
||||
|
||||
brief "call external process as pipe"
|
||||
$ entry $ bindMatch "proc:pipe" \case
|
||||
|
||||
[StringLike name, ListVal (StringLikeList params), TextLike input ] -> lift do
|
||||
mkStr @c <$> pipeProcText name params input
|
||||
|
||||
_ -> throwIO (BadFormException @c nil)
|
||||
|
||||
|
||||
entry $ bindMatch "grep" \case
|
||||
[TextLike needle, what ] | matchOne needle what
|
||||
-> pure what
|
||||
|
|
Loading…
Reference in New Issue