add --println option
This commit is contained in:
parent
97d3e34c91
commit
1c12c3bfe5
2 changed files with 28 additions and 9 deletions
24
README.md
24
README.md
|
|
@ -48,12 +48,12 @@ You may also download a binary from [Github](https://github.com/borkdude/babashk
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
``` shellsession
|
``` shellsession
|
||||||
... | bb [--raw] '<Clojure form>'
|
... | bb [--raw] [--println] '<Clojure form>'
|
||||||
```
|
```
|
||||||
|
|
||||||
There is one special variable, `*in*`, which is the input read from stdin. When
|
There is one special variable, `*in*`, which is the input read from stdin. The
|
||||||
the `--raw` flag is provided, `*in*` is a single string or vector of
|
input is read as EDN by default, unless the `--raw` flag is provided. When using
|
||||||
strings. When it is omitted, the input is read as EDN.
|
the `--println` flag, the output is printed using `println` instead of `prn`.
|
||||||
|
|
||||||
The current version can be printed with:
|
The current version can be printed with:
|
||||||
|
|
||||||
|
|
@ -93,6 +93,22 @@ $ ls | bb --raw '(filterv #f(re-find #r "reflection" %) *in*)'
|
||||||
["reflection.json"]
|
["reflection.json"]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Shuffle the lines of a file:
|
||||||
|
|
||||||
|
``` shellsession
|
||||||
|
$ cat /tmp/test.txt
|
||||||
|
1 Hello
|
||||||
|
2 Clojure
|
||||||
|
3 Babashka
|
||||||
|
4 Goodbye
|
||||||
|
|
||||||
|
$ cat /tmp/test.txt | bb --raw '(shuffle *in*)' | bb --println '(str/join "\n" *in*)'
|
||||||
|
3 Babashka
|
||||||
|
2 Clojure
|
||||||
|
4 Goodbye
|
||||||
|
1 Hello
|
||||||
|
```
|
||||||
|
|
||||||
Find the line numbers where the word Clojure occurs using a case insensitive regex:
|
Find the line numbers where the word Clojure occurs using a case insensitive regex:
|
||||||
|
|
||||||
``` shellsession
|
``` shellsession
|
||||||
|
|
|
||||||
|
|
@ -28,24 +28,27 @@
|
||||||
current-opt))
|
current-opt))
|
||||||
opts-map))
|
opts-map))
|
||||||
version (boolean (get opts "--version"))
|
version (boolean (get opts "--version"))
|
||||||
raw (boolean (get opts "--raw"))]
|
raw (boolean (get opts "--raw"))
|
||||||
|
println? (boolean (get opts "--println"))]
|
||||||
{:version version
|
{:version version
|
||||||
:raw raw}))
|
:raw raw
|
||||||
|
:println? println?}))
|
||||||
|
|
||||||
(defn -main
|
(defn -main
|
||||||
[& args]
|
[& args]
|
||||||
(let [{:keys [:version :raw]} (parse-opts args)]
|
(let [{:keys [:version :raw :println?]} (parse-opts args)]
|
||||||
(cond version
|
(cond version
|
||||||
(println (str/trim (slurp (io/resource "BABASHKA_VERSION"))))
|
(println (str/trim (slurp (io/resource "BABASHKA_VERSION"))))
|
||||||
:else
|
:else
|
||||||
(let [expr (if raw (second args) (first args))
|
(let [expr (last args)
|
||||||
expr (read-edn expr)
|
expr (read-edn expr)
|
||||||
in (slurp *in*)
|
in (slurp *in*)
|
||||||
in (if raw
|
in (if raw
|
||||||
(str/split in #"\n")
|
(str/split in #"\n")
|
||||||
(read-edn (format "[%s]" in)))
|
(read-edn (format "[%s]" in)))
|
||||||
in (if (= 1 (count in)) (first in) in)]
|
in (if (= 1 (count in)) (first in) in)]
|
||||||
(prn (i/interpret expr in))))))
|
((if println? println prn)
|
||||||
|
(i/interpret expr in))))))
|
||||||
|
|
||||||
;;;; Scratch
|
;;;; Scratch
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue