https://github.com/r0man/commandline-clj
Clojure command line parsing library.
https://github.com/r0man/commandline-clj
Last synced: 3 months ago
JSON representation
Clojure command line parsing library.
- Host: GitHub
- URL: https://github.com/r0man/commandline-clj
- Owner: r0man
- Created: 2011-09-25T15:02:36.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2019-12-19T22:01:37.000Z (about 6 years ago)
- Last Synced: 2025-10-02T04:57:13.761Z (3 months ago)
- Language: Clojure
- Homepage:
- Size: 42 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
* commandline-clj
[[https://clojars.org/commandline-clj][https://img.shields.io/clojars/v/commandline-clj.svg]]
[[https://travis-ci.org/r0man/commandline-clj][https://travis-ci.org/r0man/commandline-clj.svg]]
[[http://jarkeeper.com/r0man/commandline-clj][http://jarkeeper.com/r0man/commandline-clj/status.svg]]
[[http://jarkeeper.com/r0man/commandline-clj][https://jarkeeper.com/r0man/commandline-clj/downloads.svg]]
Parse command line options in [[https://clojure.org][Clojure]] via [[https://commons.apache.org/proper/commons-cli/index.html][Apache Commons CLI]].
[[https://xkcd.com/1168][https://imgs.xkcd.com/comics/tar.png]]
** Usage
#+BEGIN_SRC clojure :exports code :results silent
(use 'commandline.core)
(def command-line-arguments
["-a" "--almost-all" "--block-size" "10" "-c" "-t" "2011-09-25T16:45" "-I" "1,2,3" "FILE"])
(with-commandline
[[options arguments] command-line-arguments]
[[a all "do not hide entries starting with ."]
[A almost-all "do not list implied . and .."]
[b escape "print octal escapes for nongraphic characters"]
[t time "the time" :time]
[nil block-size "use SIZE-byte blocks" :integer "SIZE"]
[B ignore-backups "do not list implied entried ending with ~"]
[c nil (str "with -lt: sort by, and show, ctime (time of last modification of file status information)\n"
"with -l: show ctime and sort by name otherwise: sort by ctime")]
[C nil "list entries by columns"]
[I ids "list of integers" :integers "IDS"]]
;; The parsed command line options are bound to `options` as a map.
(assert (= options
{:block-size 10
:escape false
:ignore-backups false
:almost-all true
:I [1 2 3]
:A true
:time #inst "2011-09-25T16:45:00.000Z"
:ids [1 2 3]
:B false
:C false
:all true
:c true
:b false
:t #inst "2011-09-25T16:45:00.000Z"
:a true}))
;; All pending arguments are bound to `arguments`.
(assert (= arguments ["FILE"]))
(print-usage "ls")
;;=> usage: ls [-a] [-A] [-b] [-B] [--block-size ] [-c] [-C] [-I ] [-t ]
(print-help "ls")
;;=> usage: ls
;;=> -A,--almost-all do not list implied . and ..
;;=> -a,--all do not hide entries starting with .
;;=> -b,--escape print octal escapes for nongraphic characters
;;=> -B,--ignore-backups do not list implied entried ending with ~
;;=> --block-size use SIZE-byte blocks
;;=> -c with -lt: sort by, and show, ctime (time of last modification of file status information)
;;=> with -l: show ctime and sort by name otherwise: sort by ctime
;;=> ctime and sort by name otherwise: sort by ctime
;;=> -C list entries by columns
)
#+END_SRC
** License
Copyright (C) 2011-2016 r0man
Distributed under the Eclipse Public License, the same as Clojure.