-
Notifications
You must be signed in to change notification settings - Fork 0
/
col-jk
executable file
·47 lines (39 loc) · 1.05 KB
/
col-jk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env joker
(ns script
(:require [joker.tools.cli :as cli]
[joker.os :as os]))
(def VERSION "1")
(def opts
[[nil "--skip" "Skip first line?"]
["-v" "--version" "Show version information"]
["-h" "--help" "Show this summary"]])
(defn show-options
[summary errors]
(println "Options")
(println summary)
(when errors
(println "\nErrors:")
(run! println errors)))
(defn doit
[skip args]
(let [{:keys [success out err]}
(os/exec "awk" {:stdin :pipe
:args [(str (when skip "NR>1 ")
"{print $" (or (first args) 2) "}")]})]
(if success
(print out)
(binding [*out* *err*]
(print err)))))
(let [{:keys [options arguments summary errors]} (cli/parse-opts *command-line-args* opts)
{:keys [help version skip]} options]
(cond
errors
(do
(show-options summary errors)
(os/exit -1))
help
(show-options summary nil)
version
(println "Version:" VERSION)
:else
(doit skip arguments)))