<commit_before>(ns utree.core
  (:require (utree.dot))
  (:require (clojure [string :as str]))
  (:gen-class))

(defn ^{:cli true :usage "filename"} dot
  "Generate dot files from utility trees"
  [filename]
  (utree.dot/dot filename))

(defn subcommands
  []
  (filter :cli (map (fn [[k v]] (meta v)) (ns-publics 'utree.core))))

(defn find-first
  [pred coll]
  (first (filter pred coll)))

(defn var-named?
  [n v]
  (= (:name v) (symbol n)))

(defn lookup-command
  [name]
  (find-first (partial var-named? name) (subcommands)))

(defn command-help
  []
  (println "Usage: utree [subcommand] command-options")
  (println "\nSubcommands:")
  (doseq [c (subcommands)]
    (apply print (interpose "\t" (map c [:name :usage :doc])))
    (println)))

(defn -main
  ([] (command-help))
  ([cmd & args]
     (if-let [cmdfn (lookup-command cmd)]
       (cmdfn args)
       (println "Unrecognized subcommand" cmd))))
<commit_msg>add a subcommand "help" to display usage<commit_after>(ns utree.core
  (:require (utree.dot))
  (:require (clojure [string :as str])
            (clojure [pprint :only (cl-format)]))
  (:gen-class))

(defn ^{:cli true :usage "filename"} dot
  "Generate dot files from utility trees"
  [filename]
  (utree.dot/dot filename))

(defn ^{:cli true :usage ""} help
  "Display help message"
  []
  (command-help))

(defn subcommands
  []
  (filter :cli (map meta (vals (ns-publics 'utree.core)))))

(defn find-first
  [pred coll]
  (first (filter pred coll)))

(defn var-named?
  [n v]
  (= (:name v) (symbol n)))

(defn lookup-command
  [name]
  (find-first (partial var-named? name) (subcommands)))

(defn command-help
  []
  (println "Usage: utree subcommand [command-options]")
  (println "\nSubcommands:")
  (doseq [c (subcommands)]
    (clojure.pprint/cl-format true "~10A~30A~40A~%" (:name c) (:usage c) (:doc c)))
  (println))

(defn -main
  ([] (command-help))
  ([cmd & args]
     (if-let [cmdfn (lookup-command cmd)]
       (cmdfn args)
       (println "Unrecognized subcommand" cmd))))

{'fraction_non_alphanumeric': 0.18213399503722083, 'fraction_numerical': 0.002977667493796526, 'mean_word_length': 3.6451612903225805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3697814', 'n_tokens_mistral': 770, 'n_tokens_neox': 743, 'n_words': 212}