   (:gen-class)
   (:require [clojure.tools.cli :as cli]
             [clojure.tools.logging :as log]
+            [cheshire.core :as json]
             [monocle.io :as io]
             [monocle.rabbitmq :as rmq])
   (:use [monocle.io :only [with-offset]]))

   ["--trustpw" "Trust keystore password"]
   ["--index" (str "Format the batches in elasticsearch's bulk\n"
                   "                                "
                   " format.  Also need --type.")
    "--type " "The type to provide to elasticsearch"]
   ["-h" "--help" "Help!" :default false :flag true]])

(defn amqp-opts [iface]

(defn delete-trailing-whitespace [s]
  (.replaceAll s "[ ]+\n" "\n"))

(defn mixmatch [& args]
  (= 2 (count (set (map boolean args)))))

(defn exit [cont msg]
  (println msg)
  (reset! cont false))

(defn fail [cont err]
  (log/fatalf err)
  (reset! cont false))

(defn -main [& args]
  (let [[{:keys [interface file offset-file
                 batch help index type] :as opts} args helpstr]
        (apply cli/cli args options)
        opts (assoc opts :ssl (select-keys opts [:client :clientpw
                                                 :trust :trustpw]))
        continue? (atom true)]
    (when-not offset-file
      (fail continue? "-o not supplied"))
    (when-not file
      (fail continue? "-f not supplied"))
    (when (mixmatch index type)
      (fail continue? "supply both --index and --type if you want ES bulk"))
    (when help
      (exit continue? (delete-trailing-whitespace helpstr)))
    (when @continue?
      (main opts))))
