From fb35215fccb9cde7c3302d06f4303aedde8aad40 Mon Sep 17 00:00:00 2001 From: Frank Doepper Date: Fri, 6 Dec 2019 22:41:21 +0100 Subject: [PATCH] simplify printparam use --- Network/AMQP/Utils/Connection.hs | 2 +- Network/AMQP/Utils/Helpers.hs | 15 +++++++++++++++ agitprop.hs | 2 +- konsum.hs | 8 ++++---- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Network/AMQP/Utils/Connection.hs b/Network/AMQP/Utils/Connection.hs index 24a25e2..327878c 100644 --- a/Network/AMQP/Utils/Connection.hs +++ b/Network/AMQP/Utils/Connection.hs @@ -18,7 +18,7 @@ import System.X509 connect :: Args -> IO (Connection, Channel) connect args = do printparam "server" $ server args - printparam "port" $ show $ port args + printparam "port" $ port args printparam "vhost" $ vHost args printparam "connection_name" $ connectionName args printparam "connect timeout" $ (show (connect_timeout args)) ++ "s" diff --git a/Network/AMQP/Utils/Helpers.hs b/Network/AMQP/Utils/Helpers.hs index a6db9ea..6e13515 100644 --- a/Network/AMQP/Utils/Helpers.hs +++ b/Network/AMQP/Utils/Helpers.hs @@ -36,9 +36,24 @@ class Flexprint a where instance Flexprint (Maybe String) where flexprint = fmap (hPutStrLn stderr) +instance Flexprint (Maybe Int) where + flexprint = fmap (hPutStrLn stderr . show) + instance Flexprint String where flexprint x = flexprint (Just x) +instance Flexprint [String] where + flexprint = flexprint . unwords + +instance Flexprint Bool where + flexprint = flexprint . show + +instance Flexprint Int where + flexprint = flexprint . show + +instance Flexprint T.Text where + flexprint = flexprint . T.unpack + -- | optional or required parameters printparam :: Flexprint a => String -> a -> IO () printparam labl x = printwithlabel labl $ flexprint x diff --git a/agitprop.hs b/agitprop.hs index a34aec0..95cad41 100644 --- a/agitprop.hs +++ b/agitprop.hs @@ -47,7 +47,7 @@ main = do else "" (conn, chan) <- connect args addChannelExceptionHandler chan (X.throwTo tid) - printparam "confirm mode" $ show $ confirm args + printparam "confirm mode" $ confirm args if (confirm args) then do confirmSelect chan False diff --git a/konsum.hs b/konsum.hs index d00954f..a68acb8 100644 --- a/konsum.hs +++ b/konsum.hs @@ -22,7 +22,7 @@ main = do (conn, chan) <- connect args addChannelExceptionHandler chan (X.throwTo tid) -- set prefetch - printparam "prefetch" $ show $ preFetch args + printparam "prefetch" $ preFetch args qos chan 0 (fromIntegral $ preFetch args) False -- attach to given queue? or build exclusive queue and bind it? queue <- @@ -30,11 +30,11 @@ main = do (tempQueue chan (tmpQName args) (bindings args) (currentExchange args)) (return) (fmap T.pack (qName args)) - printparam "queue name" $ T.unpack queue - printparam "shown body chars" $ fmap show $ anRiss args + printparam "queue name" queue + printparam "shown body chars" $ anRiss args printparam "temp dir" $ tempDir args printparam "callback" $ fileProcess args - printparam "callback args" $ listToMaybeUnwords addiArgs + printparam "callback args" $ addiArgs -- subscribe to the queue ctag <- consumeMsgs -- 2.39.5