 
 (defn validate-arg-against-set
   "Validates the passed argument against the expected set."
-  [arg arg-type valid-args]
-  (or (contains? valid-args arg)
-      (str "Invalid " arg-type ". Expected one of " valid-args ". Got '" (left-string arg 40) "'")))
+  [arg arg-name valid-set]
+  (or (contains? valid-set arg)
+      (str "Invalid " arg-name ". Expected one of " valid-set ". Got '" (left-string arg 40) "'")))
 
 (defn justify-style?
   [arg]

  (.warn js/console (apply str args))
  false)

(defn extract-arg-data
  "Package up all the relevant data for validation purposes from the xxx-args-desc map into a new map."
  [args-desc]
  {:names       (set (map :name args-desc))
   :required    (->> args-desc
                     (filter :required)
                     (map :name)
                     set)
   :validate-fns (filter :validate-fn args-desc)})

;; ----------------------------------------------------------------------------
;; Primary validation functions
;; ----------------------------------------------------------------------------

(defn args-names-valid?
  "Checks that arg names passed in are all one of the expected ones. If so, returns true. Prints errors to console."
  [defined-args passed-args]
  (or (superset? defined-args passed-args)
      (let [missing-args (remove defined-args passed-args)]
        (log-error "Invalid arguments: " missing-args))))

(defn required-args-passed?
  "Checks that all :required args are included in the arg list. If so, returns true. Prints errors to console"
  [required-args passed-args]
  (or (superset? passed-args required-args)
      (let [missing-args (remove passed-args required-args)]

                           (false?  validate-result) (log-error "Argument '" arg-name "' validation failed. Expected '" (:type v-arg-def) "'. Got '" (left-string arg-val 40) "'")
                           (string? validate-result) (log-error validate-result)
                           :else                     (log-error "Invalid return from validate-fn: " validate-result))))]
    (->> (select-keys args-with-validators (vec (keys passed-args)))
         (map validate-arg)
         (every? true?))))

