-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#+TITLE: Скрипты на Clojure, Babashka runtime | ||
|
||
#+begin_quote | ||
Познакомимся с проектом babashka для написания скриптов на Clojure; | ||
Научимся создавать command line interface для своих скриптов, | ||
автоматизировать рутинные задачи с использованием babashka tasks. | ||
#+end_quote | ||
|
||
* [[https://babashka.org/][Babashka]] | ||
|
||
Диалект Clojure, имеющий [[https://github.com/babashka/babashka#differences-with-clojure][некоторые отличия]] от оригинала. | ||
|
||
** Основы | ||
|
||
#+BEGIN_SRC shell :results verbatim | ||
|
||
echo "Hello" | bb -e '(str *input* ", World!")' | ||
|
||
bb '(+ 1 2 3)' | ||
|
||
#+END_SRC | ||
|
||
#+BEGIN_SRC shell :results verbatim | ||
|
||
echo "{:a 42 :b 100}" | \ | ||
bb -IO -e '(let [[{:keys [a b]} & _] *input*] {:result (+ a b)})' | ||
|
||
#+END_SRC | ||
|
||
** Вызов внешних команд | ||
|
||
#+BEGIN_SRC clojure | ||
|
||
(println (:out (shell/sh "echo" "123"))) | ||
|
||
#+END_SRC | ||
|
||
#+BEGIN_SRC clojure | ||
|
||
(prn (shell/sh "echo" "123")) | ||
|
||
#+END_SRC | ||
|
||
#+BEGIN_SRC clojure :backend babashka | ||
|
||
(println '((1 2 3) (4 5 6))) | ||
|
||
#+END_SRC | ||
|
||
** CLI args ([[https://github.com/babashka/cli][babashka.cli]]) | ||
|
||
#+BEGIN_SRC clojure | ||
|
||
(require '[babashka.cli :as cli]) | ||
|
||
(cli/parse-args ["--output" "foo.txt" "--" "bar"]) | ||
|
||
(cli/parse-opts ["--port=8080"] {:coerce {:port :int}}) | ||
|
||
(cli/parse-args ["--verbose"]) | ||
|
||
#+END_SRC | ||
|
||
** Задачи и [[file:bb.edn][bb.edn]] | ||
|
||
Список задач: | ||
|
||
#+BEGIN_SRC shell :results verbatim | ||
|
||
bb tasks | ||
|
||
#+END_SRC | ||
|
||
Выполнение задачи: | ||
|
||
#+BEGIN_SRC shell | ||
|
||
bb run grep-me | ||
|
||
#+END_SRC |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{:tasks | ||
{hi | ||
{:doc "Greets you" | ||
:task (shell "echo 123")} | ||
|
||
hihi | ||
(do (run 'hi) | ||
(run 'hi)) | ||
|
||
grep-me | ||
(-> (shell {:out :string} "echo -n '123\n456\n") | ||
(shell "grep 5"))}} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bb -I | ||
|
||
(defn sum-a-and-b [] | ||
(let [[{:keys [a b]} & _] *input*] | ||
{:result (+ a b)})) | ||
|
||
(prn (sum-a-and-b)) |