@@ -41,21 +41,33 @@ Tools](https://lambdaisland.com/blog/2020-07-28-well-behaved-command-line-tools)
4141
4242## Getting Started
4343
44- Here, we will explain how to use ` com.lambdaisland/cli ` to create a simple script that can print out the options it receives and handle basic help.
44+ We'll use ` com.lambdaisland/cli ` to create a simple script that can print out
45+ the options it receives and handle basic help.
46+
47+ This assumes [ Babashka] ( https://babashka.org/ ) is installed, so ` bb ` should be
48+ on your shell's ` PATH ` . To use lambdaisland/cli with plain Clojure instead, use
49+ ` deps.edn ` instead of ` bb.edn ` , and ` clojure ` instead of ` bb ` .
50+
51+ ```
52+ $ bb --version
53+ $ clojure --version
54+ ```
4555
4656### Step 1: Create the Basic Command
4757
48- Init the ` bb.edn ` with
58+ Start by creating a ` bb.edn ` file (or ` deps.edn ` when using ` clojure ` ):
4959
50- ```
60+ ``` clj
5161{:deps {com.lambdaisland/cli {:mvn/version " 1.25.107" }}}
5262```
5363
54- Create a file (e.g., ` cli-test.bb ` ):
64+ Create a file (e.g., ` cli-test ` ):
5565
56- ```
66+ ``` clj
5767#! /usr/bin/env bb
5868
69+ # alternatively: #!/usr/bin/env clojure
70+
5971(require
6072 '[lambdaisland.cli :as cli]
6173 '[clojure.pprint :as pprint])
@@ -70,24 +82,31 @@ Create a file (e.g., `cli-test.bb`):
7082(cli/dispatch #'cli-test)
7183```
7284
73- Run it:
85+ Make it executable :
7486
87+ ``` shell
88+ chmod +x cli-test
7589```
76- $ bb cli-test.bb --help
90+
91+ Run it:
92+
93+ ``` shell
94+ $ ./cli-test --help
7795NAME
7896 cli-test —— Ground breaking tool breaks new ground.
7997
8098SYNOPSIS
8199 cli-test [< args> ...]
82100```
83101
84- By passing a function var (` #'cli-test ` ), the library automatically infers the name and docstring for help output.
102+ By passing a function var (` #'cli-test ` ), the library automatically infers the
103+ name and docstring for help output.
85104
86105### Step 2: Pass Arguments and Flags
87106
88107Run it with some input
89108
90- ```
109+ ``` clj
91110$ bb cli-test.bb --abc -xxy hello --format=txt world
92111{:lambdaisland.cli/argv [" hello" " world" ]
93112 :abc 1
@@ -114,7 +133,7 @@ more like a map.
114133
115134Modify your ` cli-test.bb ` to include a ` :flags ` configuration:
116135
117- ```
136+ ``` clj
118137(cli/dispatch
119138 {:name " cli-test"
120139 :command #'cli-test ; The function to call
@@ -124,7 +143,7 @@ Modify your `cli-test.bb` to include a `:flags` configuration:
124143
125144Run the updated help:
126145
127- ```
146+ ``` shell
128147$ bb cli-test.bb --help
129148NAME
130149 cli-test —— Ground breaking tool breaks new ground.
@@ -139,7 +158,7 @@ FLAGS
139158
140159Run the tool with the new flags:
141160
142- ```
161+ ``` clj
143162$ bb cli-test.bb -vvv --input=world.txt
144163{:lambdaisland.cli/argv [],
145164 :verbose 3 ,
0 commit comments