Created
October 7, 2013 00:11
-
-
Save syou6162/6860778 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#_(defdeps | |
[[org.clojure/clojure "1.5.1"] | |
[info.yasuhisay/clj-utils "0.1.1"] | |
[org.clojure/tools.cli "0.2.1"]]) | |
(ns info.yasuhisay.dep-util | |
(:use [clojure.string :only (split)]) | |
(:use [clj-utils.random :only (shuffle-with-random)]) | |
(:require [clojure.tools.cli :as cli])) | |
(defn- get-cli-opts [args] | |
(cli/cli args | |
["-h" "--help" "Show help" :default false :flag true] | |
["--filename" "Filename to be read"] | |
["--k" "Number to output sentences" :default 10 :parse-fn #(Integer. %)])) | |
(let [[options rest-args banner] (get-cli-opts *command-line-args*)] | |
(when (:help options) | |
(println banner) | |
(System/exit 0)) | |
(let [results (->> (split (slurp (:filename options)) #"\n\n") | |
(shuffle-with-random) | |
(take (:k options)))] | |
(doseq [sent results] | |
(println (str sent "\n"))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment