From fdebcd98c7246c1abb84269163f47115fb84d5a5 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 1 Mar 2016 11:17:05 +0100 Subject: draftReplace & cleanup --- tprint/src/Main.hs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'tprint/src') diff --git a/tprint/src/Main.hs b/tprint/src/Main.hs index 71bbb2f..fa5cd26 100644 --- a/tprint/src/Main.hs +++ b/tprint/src/Main.hs @@ -51,6 +51,14 @@ withInput :: Input -> (Handle -> IO a) -> IO a withInput (_, Stdin) = ($ stdin) withInput (_, ReadFile f) = withFile f ReadMode +withPrintout :: Input -> (Printout -> IO a) -> IO a +withPrintout input a = withInput input $ \inH -> do + let + p' + | (BBCode, _) <- input = either throwM return . bbcode =<< T.hGetContents inH + | otherwise = either (throwM . userError) return . eitherDecode' =<< LCBS.hGetContents inH + a =<< (force <$> p') + humanJobStatus :: JobStatus -> Maybe PrinterId -> String humanJobStatus (Queued (PrinterId n)) Nothing = "queued at printer #" ++ show n humanJobStatus (Queued _) _ = "queued" @@ -104,26 +112,20 @@ tprint TPrint{ operation = Job{..}, ..} Client{..} out = job jobId >>= format | otherwise <- output = T.hPutStrLn out =<< either throwM return (cobbcode p) -- Mutate -tprint TPrint{ operation = JobCreate{..}, ..} client@Client{..} out = withInput input $ \inH -> do +tprint TPrint{ operation = JobCreate{..}, ..} client@Client{..} out = withPrintout input $ \p -> do let - p' - | (BBCode, _) <- input = either throwM return . bbcode =<< T.hGetContents inH - | otherwise = either (throwM . userError) return . eitherDecode' =<< LCBS.hGetContents inH block' | block = blockLoop client out | otherwise = hPutStrLn out . show - p <- force <$> p' unless dryRun $ block' =<< jobCreate printer p tprint TPrint{ operation = JobDelete{..}, ..} Client{..} _ = unless dryRun $ jobDelete jobId -tprint TPrint{ operation = DraftCreate{..}, ..} Client{..} out = withInput input $ \inH -> do - let - p' - | (BBCode, _) <- input = either throwM return . bbcode =<< T.hGetContents inH - | otherwise = either (throwM . userError) return . eitherDecode' =<< LCBS.hGetContents inH - p <- force <$> p' +tprint TPrint{ operation = DraftCreate{..}, ..} Client{..} out = withPrintout input $ \p -> do unless dryRun $ hPutStrLn out . show =<< draftCreate draftTitle p +tprint TPrint{ operation = DraftReplace{..}, ..} Client{..} _ = withPrintout input $ \p -> do + unless dryRun $ draftReplace draftId draftTitle p + tprint _ _ _ = undefined -- cgit v1.2.3