 
 ;; run
 
-(defn- emit-start [load-builds-from accumulate-stages-for-pipelines pipeline-stages]
+(defn- emit-start [sync-start-time aggregate-jobs-for-pipelines pipeline-stages]
   (println "Looking at pipeline groups" (distinct (map :group pipeline-stages)))
-  (println "Syncing all builds starting from" (tf/unparse (:date-time tf/formatters) load-builds-from))
-  (when (some? accumulate-stages-for-pipelines)
-    (println "Aggregating jobs for stages of" accumulate-stages-for-pipelines))
-
-  (println "Finding all builds for syncing...")
+  (println "Syncing all stages starting from" (tf/unparse (:date-time tf/formatters) sync-start-time))
+  (when (some? aggregate-jobs-for-pipelines)
+    (println "Aggregating jobs for stages of" aggregate-jobs-for-pipelines))
+
+  (println "Finding all pipeline runs for syncing...")
 
   pipeline-stages)
 
 (defn- emit-count-items [builds]
-  (println (format "Found %s builds to be synced, starting" (count builds)))
+  (println (format "Found %s stage instances to be synced, starting" (count builds)))
   builds)
 
 (defn- emit-end [builds]
-  (println)
-  (println (format "Done, wrote %s build entries" (count builds))))
+  (let [build-count (count builds)]
+    (println)
+    (println (format "Done, wrote %s build entries" build-count))))
 
 (defn -main [& c-args]
   (def args (parse-opts c-args cli-options))


  (println "Go" go-url "-> buildviz" buildviz-url)

  (let [load-builds-from (get-start-date (:load-builds-from (:options args)))
        accumulate-stages-for-pipelines (set (:aggregate-jobs-for-pipelines (:options args)))
        selected-pipeline-group-names (set (drop 1 (:arguments args)))]

    (->> (goapi/get-stages go-url)
         (select-stages selected-pipeline-group-names)
         (emit-start load-builds-from accumulate-stages-for-pipelines)
         (mapcat (partial job-instances-for-stage load-builds-from accumulate-stages-for-pipelines))
         (sort-by :scheduledDateTime)
         emit-count-items
         (map augment-job-with-inputs)
         (map job-data-for-instance)
         (filter #(some? (:build %)))
         (map augment-job-instance-with-junit-xml)
         (map make-build-instance)
         (map put-to-buildviz)
         emit-end)))

    :id :buildviz-url
    :default "http://localhost:3000"]
   ["-f" "--from DATE" "DATE from which on builds are loaded (by default tries to pick up where the last run finished)"
    :id :sync-start-time
    :parse-fn #(tf/parse date-formatter %)]
   ["-s" "--aggregate PIPELINE" "PIPELINE for which a complete stage will be synced as a job"
    :id :aggregate-jobs-for-pipelines
