]> woffs.de Git - fd/haskell-amqp-utils.git/commitdiff
small doc updates
authorFrank Doepper <[email protected]>
Fri, 22 Jun 2018 19:02:29 +0000 (21:02 +0200)
committerFrank Doepper <[email protected]>
Fri, 22 Jun 2018 19:02:29 +0000 (21:02 +0200)
Network/AMQP/Utils/Connection.hs
Network/AMQP/Utils/Helpers.hs
Network/AMQP/Utils/Options.hs
agitprop.hs
konsum.hs

index 3467a12d6e2c709db266a86ac6bbeb93e1464828..3ee8afed3546f68b2982c9cec682692c89892e1f 100644 (file)
@@ -13,6 +13,7 @@ import qualified Network.Connection         as N
 import           System.X509
 import           Data.Default.Class
 
+-- | opens a connection and a channel
 connect :: Args -> IO (Connection,Channel)
 connect args = do
     printparam' "server" $ server args
@@ -55,7 +56,7 @@ connect args = do
 --                  (\_ _ _ -> return ValidationCachePass)
 --                  (\_ _ _ -> return ())
 
--- client certificate
+-- | provides the TLS client certificate
 myCert :: Maybe FilePath -> Maybe FilePath -> t -> IO (Maybe Credential)
 myCert (Just cert') (Just key') _ = do
     result <- credentialLoadX509 cert' key'
index ebeaa5db4d831e11f5ebc6f8b25d04b20d348184..e35f03ddbaab69e672fefb7780683d951a00ee56 100644 (file)
@@ -3,12 +3,12 @@ module Network.AMQP.Utils.Helpers where
 import qualified Data.ByteString.Lazy.Char8 as BL
 import           System.IO
 
--- log cmdline options
+-- log cmdline options
 listToMaybeUnwords :: [String] -> Maybe String
 listToMaybeUnwords [] = Nothing
 listToMaybeUnwords x = Just $ unwords x
 
--- Strings or ByteStrings with label, oder nothing at all
+-- Strings or ByteStrings with label, oder nothing at all
 printwithlabel :: String -> Maybe (IO ()) -> IO ()
 printwithlabel _ Nothing =
     return ()
@@ -17,21 +17,21 @@ printwithlabel labl (Just i) = do
     i
     hFlush stdout
 
--- optional parameters
+-- optional parameters
 printparam :: String -> Maybe String -> IO ()
 printparam labl ms = printwithlabel labl $
     fmap putStrLn ms
 
--- required parameters
+-- required parameters
 printparam' :: String -> String -> IO ()
 printparam' d s = printparam d (Just s)
 
--- head chars of body
+-- head chars of body
 printbody :: (String, Maybe BL.ByteString) -> IO ()
 printbody (labl, ms) = printwithlabel labl $
     fmap (\s -> putStrLn "" >> BL.putStrLn s) ms
 
--- log marker
+-- log marker
 hr :: String -> IO ()
 hr x = putStrLn hr' >> hFlush stdout
   where
index 0583828c8ccb275ebf16a4c9b37a8caf5708643b..34c29be090bb88e70497e8bf727bf830b92035e8 100644 (file)
@@ -52,7 +52,7 @@ instance Default Args where
                []
                Nothing
                ""
-               ""
+               "/dev/stdin"
                False
 
 -- | Common options
@@ -158,16 +158,16 @@ kOptions = [ Option [ 'r' ]
 aOptions :: [OptDescr (Args -> Args)]
 aOptions = [ Option [ 'r' ]
                     [ "routingkey" ]
-                    (ReqArg (\s o -> o { rKey = s }) "BINDINGKEY")
-                    ("AMQP binding key (default: #)")
+                    (ReqArg (\s o -> o { rKey = s }) "ROUTINGKEY")
+                    ("AMQP routing key (default: " ++ (rKey def) ++ ")")
            , Option [ 'f' ]
                     [ "inputfile" ]
                     (ReqArg (\s o -> o { inputFile = s }) "INPUTFILE")
-                    "Message input file"
+                    ("Message input file (default: " ++ (inputFile def) ++ ")")
            , Option [ 'l' ]
                     [ "linemode" ]
                     (NoArg (\o -> o { lineMode = not (lineMode o) }))
-                    "Toggle line-by-line mode"
+                    ("Toggle line-by-line mode (default: " ++ show (lineMode def) ++ ")")
            ]
 
 -- |
index 535979588a84c6feb9c9ee3d5ca47404beb265dd..1beef5f908e15b476b4f17cf156eb50593f5e51d 100644 (file)
@@ -9,6 +9,7 @@ import           Network.AMQP.Utils.Options
 import           Network.AMQP.Utils.Helpers
 import           Network.AMQP.Utils.Connection
 import qualified Data.ByteString.Lazy.Char8 as BL
+
 main :: IO ()
 main = do
     hr "starting"
index 5756b5f4ef84841f8be8208a83ef791b40d36130..08ba263774cdf57214be5973546f9b0c2e72cd7f 100644 (file)
--- a/konsum.hs
+++ b/konsum.hs
@@ -78,7 +78,7 @@ main = do
                  show (exception :: X.SomeException))
     closeConnection conn
 
--- exclusive temp queue
+-- exclusive temp queue
 tempQueue :: Channel -> String -> [(String, String)] -> String -> IO T.Text
 tempQueue chan tmpqname bindlist x = do
     (q, _, _) <- declareQueue chan
@@ -90,7 +90,7 @@ tempQueue chan tmpqname bindlist x = do
           (if null bindlist then [ (x, "#") ] else bindlist)
     return q
 
--- process received message
+-- process received message
 myCallback :: Maybe Int
            -> Maybe String
            -> Maybe String
@@ -115,7 +115,7 @@ myCallback anR filePr tempD addi tid m@(_, envi) = do
                                      tid)
     hr $ "END " ++ numstring
 
--- if the message is to be saved
+-- if the message is to be saved
 -- and maybe processed further
 optionalFileStuff :: (Message, Envelope)
                   -> [String]
@@ -140,7 +140,7 @@ optionalFileStuff (msg, envi) callbackoptions addi numstring tempD filePr tid =
                return ())
           callbackcmdline
 
--- save message into temp file
+-- save message into temp file
 saveFile :: Maybe String -> String -> BL.ByteString -> IO (Maybe String)
 saveFile Nothing _ _ = return Nothing
 saveFile (Just tempD) numstring body = do
@@ -151,7 +151,7 @@ saveFile (Just tempD) numstring body = do
     hClose h
     return $ Just p
 
--- construct cmdline for callback script
+-- construct cmdline for callback script
 constructCallbackCmdLine :: [String]
                          -> [String]
                          -> String
@@ -161,7 +161,7 @@ constructCallbackCmdLine :: [String]
 constructCallbackCmdLine opts addi num exe path =
     exe : "-f" : path : "-n" : num : opts ++ addi
 
--- call callback script
+-- call callback script
 doProc :: String -> Envelope -> [String] -> IO ()
 doProc numstring envi (exe : args) = do
     (_, _, _, processhandle) <- createProcess (proc exe args) { std_out = Inherit
@@ -178,15 +178,15 @@ formatheaders :: ((T.Text, FieldValue) -> [a]) -> FieldTable -> [a]
 formatheaders f (FieldTable ll) =
     concat $ map f $ M.toList ll
 
--- log formatting
+-- log formatting
 fieldshow :: (T.Text, FieldValue) -> String
 fieldshow (k, v) = "\n        " ++ T.unpack k ++ ": " ++ valueshow v
 
--- callback cmdline formatting
+-- callback cmdline formatting
 fieldshow' :: (T.Text, FieldValue) -> [String]
 fieldshow' (k, v) = [ "-h", T.unpack k ++ "=" ++ valueshow v ]
 
--- showing a FieldValue
+-- showing a FieldValue
 valueshow :: FieldValue -> String
 valueshow (FVString value) =
     T.unpack value
@@ -194,7 +194,7 @@ valueshow (FVInt32 value) =
     show value
 valueshow value = show value
 
--- skip showing body head if binary type
+-- skip showing body head if binary type
 isimage :: Maybe String -> Bool
 isimage Nothing = False
 isimage (Just ctype)
@@ -204,19 +204,19 @@ isimage (Just ctype)
           False
     | otherwise = any (flip isPrefixOf ctype) [ "application", "image" ]
 
--- show the first bytes of message body
+-- show the first bytes of message body
 anriss' :: Maybe Int -> BL.ByteString -> BL.ByteString
 anriss' x = case x of
     Nothing -> id
     Just y -> BL.take (fromIntegral y)
 
--- callback cmdline with optional parameters
+-- callback cmdline with optional parameters
 printopt :: (String, Maybe String) -> [String]
 printopt (_, Nothing) = []
 printopt (opt, Just s) =
     [ opt, s ]
 
--- prints header and head on STDOUT and returns cmdline options to callback
+-- prints header and head on STDOUT and returns cmdline options to callback
 printmsg :: (Message, Envelope) -> Maybe Int -> ZonedTime -> IO [String]
 printmsg (msg, envi) anR now = do
     mapM_ (uncurry printparam)
@@ -289,15 +289,18 @@ printmsg (msg, envi) anR now = do
                          timestamp'
                          timediff
 
+-- | timestamp conversion
 zonedTimeToUTCFLoor :: ZonedTime -> UTCTime
 zonedTimeToUTCFLoor x = posixSecondsToUTCTime $
     realToFrac ((floor .
                      utcTimeToPOSIXSeconds .
                          zonedTimeToUTC) x :: Timestamp)
 
+-- | show the timestamp
 showtime :: TimeZone -> Maybe UTCTime -> Maybe String
 showtime tz = fmap (show . (utcToZonedTime tz))
 
+-- | show difference between two timestamps
 difftime :: UTCTime -> UTCTime -> String
 difftime now msg
     | now == msg = "now"