clojure.contrib.command-line

179 views
Skip to first unread message

octopusgrabbus

unread,
Jul 28, 2011, 6:37:03 PM7/28/11
to Clojure
Are there any command-line examples or documentation other than what's
up on clojure.org or ClojureDocs?

I'm using

(defn -main [& args]
(with-command-line args
"Get csv file name"
[[in-file-name ".csv input file name" "resultset.csv" ]]
[[in-file-name ".csv input file name" 1]]

(println "in-file-name:", in-file-name)

If I specify a file name it does not get used. Only resultset.csv is
used.

tnx
cmn

Anthony Grimes

unread,
Jul 28, 2011, 7:24:52 PM7/28/11
to clo...@googlegroups.com
command-line is deprecated in favor of tools.cli now. http://github.com/clojure/tools.cli

octopusgrabbus

unread,
Jul 28, 2011, 9:58:35 PM7/28/11
to Clojure
Thanks. I'll switch over.

OGINO Masanori

unread,
Jul 28, 2011, 10:14:36 PM7/28/11
to clo...@googlegroups.com
(defn -main [& args]
(with-command-line args
"Get csv file name"
[[in-file-name ".csv input file name" "resultset.csv" ]]
(println "in-file-name:", in-file-name)))

The second vector of vector seems unnecessary.

Or tools.cli way:

(ns foo.main
(:gen-class)
(:use [clojure.tools.cli :only (cli optional)]))

(defn parse-opts
[args]
(cli args
(optional ["--in-file-name"
".csv input file"
:default "resultset.csv"]
identity)))

(defn -main
[& args]
(let [opts (parse-opts args)]
(println "in-file-name:" (:in-file-name opts))))

It might be verbose but I think it is more descriptive than
with-command-line one.
However, I'd like more documents and examples about tools.cli.

--
Name: OGINO Masanori (荻野 雅紀)
E-mail: masanor...@gmail.com

gaz jones

unread,
Jul 28, 2011, 10:53:23 PM7/28/11
to clo...@googlegroups.com
are there any scenarios in particular you feel need more
documentation? im happy to add more if it is lacking. hopefully the
README on the project page and tests provide a pretty good idea of
what options are available:

https://github.com/clojure/tools.cli
https://github.com/clojure/tools.cli/blob/master/src/test/clojure/clojure/tools/cli_test.clj

2011/7/28 OGINO Masanori <masanor...@gmail.com>:

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

OGINO Masanori

unread,
Jul 28, 2011, 11:24:35 PM7/28/11
to clo...@googlegroups.com
Well, README and tests are very good.
I withdrew into REPL and overlooked them stupidly. I'm very sorry.

BTW some functions seems not to be public API though they are public.
Why they are not separated by defn- or specific namespace like
clojure.tools.cli.internals?

octopusgrabbus

unread,
Jul 29, 2011, 8:56:45 AM7/29/11
to Clojure


On Jul 28, 7:24 pm, Anthony Grimes <disciplera...@gmail.com> wrote:
> command-line is deprecated in favor of tools.cli now.http://github.com/clojure/tools.cli

Where is the repository located?

(ns addr-verify
(:gen-class)
(:require [clojure.tools.cli :only (cli optional)])
.
.
.
results in this error:

clojure.lang.Compiler$CompilerException:
java.io.FileNotFoundException: Could not locate clojure/tools/
cli__init.class or clojure/tools/cli.clj on classpath:

gaz jones

unread,
Jul 29, 2011, 9:45:23 AM7/29/11
to clo...@googlegroups.com
it lives on github: http://github.com/clojure/tools.cli
like all the new contrib libs, to use it in a project you need to add
it to your dependencies:

:dependencies [[org.clojure/clojure "1.2.1"]
[org.clojure/tools.cli "0.1.0"]]

gaz jones

unread,
Jul 29, 2011, 9:48:02 AM7/29/11
to clo...@googlegroups.com
> Well, README and tests are very good.
> I withdrew into REPL and overlooked them stupidly. I'm very sorry.
>

no worries, glad they help.

> BTW some functions seems not to be public API though they are public.
> Why they are not separated by defn- or specific namespace like
> clojure.tools.cli.internals?

no reason other than its a small lib with a handful of functions...

octopusgrabbus

unread,
Jul 29, 2011, 10:06:09 AM7/29/11
to Clojure
Thanks. This fixed it.

OGINO Masanori

unread,
Jul 29, 2011, 6:11:09 PM7/29/11
to clo...@googlegroups.com
> no reason other than its a small lib with a handful of functions...
I see. Thanks.
Reply all
Reply to author
Forward
0 new messages