From 368df582c97597e51ecd0bc8a8b51c41cc233778 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 1 Mar 2016 11:13:47 +0100 Subject: draftCreate && reporting of jobIds --- tprint/src/Main.hs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'tprint/src/Main.hs') diff --git a/tprint/src/Main.hs b/tprint/src/Main.hs index f78349e..71bbb2f 100644 --- a/tprint/src/Main.hs +++ b/tprint/src/Main.hs @@ -59,17 +59,18 @@ humanJobStatus (Printing _) _ = "printing" humanJobStatus (Done) _ = "finished successfully" humanJobStatus (Failed err) _ = "failed: " ++ show err -blockLoop :: Client IO -> JobId -> IO () -blockLoop client@Client{..} jId = do +blockLoop :: Client IO -> Handle -> JobId -> IO () +blockLoop client@Client{..} out jId@(JobId n) = do threadDelay (10^6) status <- jobStatus jId case status of - Done -> return () + Done -> hPutStrLn out $ show n Failed err -> throwM err - _ -> blockLoop client jId + _ -> blockLoop client out jId tprint :: TPrint -> Client IO -> Handle -> IO () +-- Query tprint TPrint{ operation = Printers, ..} Client{..} out = printers >>= format where format ps | (Human, _) <- output = mapM_ (\(PrinterId n, st) -> hPutStrLn out $ show n ++ "\t" ++ humanStatus st) $ Map.toAscList ps @@ -102,18 +103,27 @@ tprint TPrint{ operation = Job{..}, ..} Client{..} out = job jobId >>= format | (JSON, _) <- output = LCBS.hPutStrLn out $ encodePretty p | otherwise <- output = T.hPutStrLn out =<< either throwM return (cobbcode p) -tprint TPrint{ operation = JobCreate{..}, ..} client@Client{..} _ = withInput input $ \inH -> do +-- Mutate +tprint TPrint{ operation = JobCreate{..}, ..} client@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 block' - | block = blockLoop client - | otherwise = const $ return () + | 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' + unless dryRun $ hPutStrLn out . show =<< draftCreate draftTitle p + tprint _ _ _ = undefined -- cgit v1.2.3