import Data.Default.Class
import Data.Maybe
+import qualified Data.Map as M
import Data.Text (Text, pack)
import Data.Version (showVersion)
import Network.AMQP.Types
, msgprio :: Maybe Octet
, msgcorrid :: Maybe Text
, msgexp :: Maybe Text
+ , msgheader :: Maybe FieldTable
}
instance Default Args where
Nothing
Nothing
Nothing
+ Nothing
-- | Common options
cOptions :: [OptDescr (Args -> Args)]
["msgexp"]
(ReqArg (\s o -> o {msgexp = Just $ pack s}) "EXP")
("Message Expiration")
+ , Option
+ ['h']
+ ["header"]
+ (ReqArg (\s o -> o {msgheader = addheader (msgheader o) s}) "HEADER=VALUE")
+ ("Message Headers")
]
-- |
options "agitprop" = aOptions ++ cOptions
options _ = cOptions
+addheader :: Maybe FieldTable -> String -> Maybe FieldTable
+addheader Nothing string = Just $ FieldTable $ M.singleton (k string) (v string)
+addheader (Just (FieldTable oldheader)) string = Just $ FieldTable $ M.insert (k string) (v string) oldheader
+
+k :: String -> Text
+k s = pack $ takeWhile (/='=') s
+
+v :: String -> FieldValue
+v s = FVString $ pack $ tail $ dropWhile (/='=') s
+
-- | 'parseargs' exename argstring
-- applies options onto argstring
parseargs :: String -> [String] -> IO Args
-- | Publish one message with our settings
publishOneMsg' :: Channel -> Args -> BL.ByteString -> IO ()
publishOneMsg' c a f = do
- now <- getCurrentTime >>= return.utcTimeToPOSIXSeconds >>= return.floor
+ now <- getCurrentTime >>= return.floor.utcTimeToPOSIXSeconds
r <-
publishMsg
c
, msgPriority = msgprio a
, msgCorrelationID = msgcorrid a
, msgExpiration = msgexp a
- -- , msgHeaders =
+ , msgHeaders = msgheader a
}
printparam "sent" $ fmap show r