                          (map :project)
                          (str/join ",")))))
 
-(defn list [target-projects {source-project-name :name :as source-project-desc}]
+(defn list [target-projects {source-project :name :as source-project-desc}]
   (let [all-projects-desc (-> target-projects
                               (read-all-target-project-clj)
-                              (assoc (keyword source-project-name) source-project-desc))]
+                              (assoc (keyword source-project) source-project-desc))]
     (list-resources all-projects-desc namespace-def)
     (list-resources all-projects-desc resource-def)))
    (update-resource! resource target-project source-project-desc (project-clj-of target-projects-desc target-project)))
  (m/info "*\n****************************************************************\n"))

(defn aggregate-result [result ns p]
  (if (contains? result ns)
    (assoc result ns (merge-with str p (get result ns)))
    (assoc result ns p)))

(defn reduce-occurence
  ([ns-occurence] (reduce-occurence ns-occurence {}))
  ([[[ns p] & r] result]
   (let [aggregated-result (aggregate-result result ns p)]
     (if (empty? r)
       aggregated-result
       (recur r aggregated-result)))))

(defn determin-occurence [projects resource-selector]
  (let [initial-m (zipmap (keys projects) (take (count projects) (repeat "")))]
    (reduce-kv
     (fn [m project desc]
       (into m
             (map (fn [ns] [(keyword ns)
                            (merge-with str {project "X"} initial-m)])
                  (get-in desc resource-selector))))
     []
     projects)))

(defn pretty-print-table [m]
  (reduce-kv
   (fn [m k v]
     (conj m (merge {:name (name k)} v)))
   []
   m))

(defn log-resouces-table [m]
  (pp/print-table (sort-by :name m))
  (m/info "\n"))

(defn build-resource-table [projects resource-selector]
  (-> projects
      (determin-occurence resource-selector)
      (reduce-occurence)
      (pretty-print-table)))

;;;;; Command Actions ;;;;;


    (m/info "To commit      : lein sync" passed-projects "--commit")
    (m/info "To push        : lein sync" passed-projects "--push")))

(defn list-resources [projects-desc selector]
  (-> projects-desc
      (build-resource-table selector)
      (log-resouces-table selector)))

;;;;; Sync Commands ;;;;;

