 (defn- exit
   "Print message and exit with status."
   [status msg]
-  (if (= status 0)
+  (if (zero? 0)
     (println msg)
     (binding [*out* *err*]
       (println msg)))

(defn- usage
  "Construct usage message."
  [options-summary]
  (->> ["A Cyanite data removal tool"
        ""
        "Usage: "
        "  cyanite-remover [options] remove-metrics <tenant> <rollup,...> <path,...> <cassandra_host,...> <elasticsearch_url>"
        "  cyanite-remover [options] remove-paths <tenant> <path,...> <elasticsearch_url>"
        "  cyanite-remover [options] remove-obsolete-data <tenant> <rollup,...> <path,...> <cassandra_host,...> <elasticsearch_url>"
        "  cyanite-remover [options] remove-empty-paths <tenant> <path,...> <elasticsearch_url>"
        "  cyanite-remover [options] list-metrics <tenant> <rollup,...> <path,...> <cassandra_host,...> <elasticsearch_url>"
        "  cyanite-remover [options] list-paths <tenant> <path,...> <elasticsearch_url>"
        "  cyanite-remover [options] list-obsolete-data <tenant> <rollup,...> <path,...> <cassandra_host,...> <elasticsearch_url>"
        "  cyanite-remover [options] list-empty-paths <tenant> <path,...> <elasticsearch_url>"
        "  cyanite-remover help"
        ""
        "Options:"
        options-summary]
       (str/join \newline)))

(defn- error-msg
  "Combine error messages."

  "Run command."
  [arguments options summary]
  (let [command (first arguments)]
    (when-not (contains? cli-commands command)
      (exit 1 (error-msg [(format "Unknown command: \"%s\"" command)])))
    (apply (resolve (symbol (str "cyanite-remover.cli/run-" command)))
           [command (drop 1 arguments) options summary])))
