 
 (def cli-options
   [["-f" "--force-update"]
+   ["-c" "--complete-follow-ups"] ;; Use with -f
    ["-s" "--self-only"]])
 
 (defn -main [& args]
   (let [{:keys [options arguments errors summary]} (parse-opts args cli-options)]
-    (println "Running bookmarks migration with options: dry-run" (not (:force-update options)) "self-only" (:self-only options))
+    (println "Running bookmarks migration with options: dry-run" (not (:force-update options))
+      "self-only" (:self-only options)
+      "complete-follow-ups" (:complete-follow-ups options))
     (let [conn (db/init-conn c/db-options)]
       (try
         (create-temp-index conn)

            (let [entries (entries-for-org conn (:uuid o))]
              (println "Org:" (:uuid o) "-" (:name o))
              (doseq [e entries]
                (migrate-follow-ups-for-entry conn e (:self-only options) (not (:force-update options)))))))
        (delete-temp-index conn)
        (exit 0 "\n")

        (catch Exception e
          (println e)
          (delete-temp-index conn)
          (exit 1 "Bookmark migration exception."))))))
                                    (:assignee %))
                            follow-ups))
        updated-bookmarks (clojure.set/union (set (map :user-id new-bookmarks)) (:bookmarks e))
        updated-follow-ups (when complete-follow-ups?
                             (mapv #(if (and (not (:completed? %))
                                               (or (not self-only?)
                                                   (and self-only?
                                                        (= (-> % :assignee :user-id) (-> % :author :user-id)))))
                                        (assoc % :completed? true)
                                        %)
                                follow-ups))]
    (println "  Updating entry:" (:uuid e))
    (println "    Adding bookmarks for:" updated-bookmarks)
    (println "    Updating follow-ups:")
    (doseq [f updated-follow-ups]
      (println "     -" (:uuid f) "completed?" (:completed? f) "self?" (= (-> f :assignee :user-id) (-> f :author :user-id))))
    (when-not dry-run?
      (if complete-follow-ups?
        (println "  Actually updating entry's bookmarks and follow-ups:" (:uuid e))
        (println "  Actually updating entry's bookmarks:" (:uuid e)))
      (entry/update-entry-no-user! conn (:uuid e) (merge e (if complete-follow-ups?
                                                             {:follow-ups updated-follow-ups
                                                              :bookmarks updated-bookmarks}
                                                             {:bookmarks updated-bookmarks}))))))

(defn- exit [status msg]
  (println msg)
