From fb76663b6f2e33dbcc93374e5202ad8e522803f0 Mon Sep 17 00:00:00 2001 From: guns Date: Tue, 18 Feb 2014 21:23:33 -0600 Subject: [PATCH] Migrate to tools.cli optparse-clj was merged into tools.cli for v0.3.0. cljs.tools.cli does not build with current deps, so we update both lein-cljsbuild and add an explicit CLJS dep (as recommended by lein-cljsbuild). Note that this new version of CLJS does not have cljs.core/format. --- project.clj | 5 +++-- src/cljx/frak.cljx | 2 +- src/cljx/frak/cli.cljx | 25 +++++++++++++------------ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/project.clj b/project.clj index bd21f8a..6bf99e7 100644 --- a/project.clj +++ b/project.clj @@ -5,8 +5,9 @@ :url "http://www.eclipse.org/legal/epl-v10.html"} :jar-exclusions [#"(?:\.(?:cljx|sw[onp])|cli\.cljs?)"] :dependencies [[org.clojure/clojure "1.5.1"] - [guns.cli/optparse "1.1.1"]] - :plugins [[lein-cljsbuild "0.3.2"] + [org.clojure/clojurescript "0.0-2156"] + [org.clojure/tools.cli "0.3.1"]] + :plugins [[lein-cljsbuild "1.0.2"] [com.keminglabs/cljx "0.3.0"]] :source-paths ["src/cljx"] :profiles {:dev {:dependencies [[criterium "0.4.1"] diff --git a/src/cljx/frak.cljx b/src/cljx/frak.cljx index 8104f4f..8566a23 100644 --- a/src/cljx/frak.cljx +++ b/src/cljx/frak.cljx @@ -118,7 +118,7 @@ (str (if (= 1 (count chars)) (first chars) - (format "[%s]" (apply str chars))) + (str \[ (apply str chars) \])) (when optional? "?"))))) (defn- render-trie-strategy [node] diff --git a/src/cljx/frak/cli.cljx b/src/cljx/frak/cli.cljx index 606d66b..7011711 100644 --- a/src/cljx/frak/cli.cljx +++ b/src/cljx/frak/cli.cljx @@ -1,7 +1,8 @@ (ns frak.cli "Command line interface." (:require [clojure.string :as string] - [guns.cli.optparse :as o] + #+clj [clojure.tools.cli :refer [parse-opts]] + #+cljs [cljs.tools.cli :refer [parse-opts]] [frak])) ;;;; Utilities @@ -34,22 +35,22 @@ (def main-flags [["-e" "--exact" "Generated pattern requires an exact match" - :key :exact?] + :id :exact?] ["-c" "--capture" "Generated pattern captures" - :key :capture?] + :id :capture?] ["-h" "--help" "Display this help message"]]) (defn -main "Passes arguments to frak/pattern" [& args] - (try - (let [[opts words summary] (o/parse args main-flags)] - (if (or (empty? words) (:help opts)) - (log (str "Usage: frak \n\nFlags:\n" summary)) - (log (frak/string-pattern words (select-keys opts [:exact? :capture?])))) - (exit 0)) - (catch #+clj AssertionError #+cljs js/Error e - (log (#+clj .getMessage #+cljs .-message e)) - (exit 1)))) + (let [{:keys [options summary errors] words :arguments} + (parse-opts args main-flags)] + (when errors + (printerr (string/join "\n" errors)) + (exit 1)) + (if (or (empty? words) (:help options)) + (log (str "Usage: frak \n\nFlags:\n" summary)) + (log (frak/string-pattern words (select-keys options [:exact? :capture?])))) + (exit 0))) #+cljs (set! *main-cli-fn* -main) -- 2.25.1