You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/clojure-cli/built-in-commands.md
+56-40Lines changed: 56 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,13 @@
1
1
# Clojure CLI Built-in commands
2
2
3
-
`clojure` without any other arguments will run a REPL with a basic terminal prompt. `clj` is a wrapper script for the `clojure` command (`rlwrap` required) to add command history to the basic REPL prompt.
3
+
`clojure` without any other arguments will run a REPL with a basic terminal prompt.
4
+
5
+
`clj` is a wrapper script for the `clojure` command (`rlwrap` required) to add command history to the basic REPL prompt.
6
+
7
+
`clojure -T:deps` to run one of several built-in commands to help work with Clojure CLI projects and libraries.
8
+
9
+
`clojure --help` list the available commands.
4
10
5
-
`clojure -T:deps` to run one of several built-in commands to help work with Clojure CLI projects and libraries. `clojure --help` list the available commands.
6
11
7
12
`-X` execution option is used for the `:deps` aliases, running them via `clojure.exec` and limiting the class path to the current directory.
8
13
@@ -40,9 +45,10 @@ The list includes transitive dependencies, library dependencies of the project l
40
45
41
46
The `:aliases '[:alias/name(s)]'` argument will also list library dependencies from a given alias, either project alias or user alias.
42
47
43
-
```shell
44
-
clojure -X:deps list
45
-
```
48
+
!!! NOTE ""
49
+
```shell
50
+
clojure -X:deps list
51
+
```
46
52
47
53
??? EXAMPLE "Dependency list from Practicalli Service project template"
Use the `:aliases '[:alias/name(s)]'` option to also include the dependencies from a project or user alias. Showing the dependencies from an aliase can useful to identify conflicting dependencies when using an alias (unlikely but it could happen).
127
133
128
-
```shell
129
-
clojure -X:deps list :aliases '[:dev/reloaded]'
130
-
```
134
+
!!! NOTE ""
135
+
```shell
136
+
clojure -X:deps list :aliases '[:dev/reloaded]'
137
+
```
131
138
132
139
??? EXAMPLE "Dependency list from project and Practicalli :dev/reloaded alias"
133
140
```shell
@@ -222,9 +229,10 @@ The tree includes transitive dependencies, library dependencies of the project l
222
229
223
230
The `:aliases '[:alias/name(s)]'` argument will also list library dependencies from a given alias, either project alias or user alias.
224
231
225
-
```shell
226
-
clojure -X:deps tree
227
-
```
232
+
!!! NOTE ""
233
+
```shell
234
+
clojure -X:deps tree
235
+
```
228
236
229
237
??? EXAMPLE "Dependency list from Practicalli Service project template"
230
238
```shell
@@ -348,9 +356,10 @@ clojure -X:deps tree
348
356
349
357
Use the `:aliases` option with the Clojure CLI in the root of a project to show library dependencies for the project and the `:dev/reloaded` alias which could be useful if there are library conflicts when using an alias (unlikely but it could happen).
350
358
351
-
```shell
352
-
clojure -X:deps tree :aliases '[:dev/reloaded]'
353
-
```
359
+
!!! NOTE ""
360
+
```shell
361
+
clojure -X:deps tree :aliases '[:dev/reloaded]'
362
+
```
354
363
355
364
The `:aliases` option can be used to inspect the dependencies of a user alias, listing only dependencies from the specified aliases when run outside of a Clojure project.
356
365
@@ -393,18 +402,20 @@ The `:aliases` option can be used to inspect the dependencies of a user alias, l
393
402
394
403
Add a jar file for a library to the local Maven repository, e.g. `~/.m2/repository`, making that library accessible to all other local projects.
Find the available versions of a given library in the form domain/library-name (domain is typically the company name or Git Service user or organisation name).
@@ -413,36 +424,40 @@ Some dependencies will require a preparation step before they can be used on the
413
424
414
425
Projects that require preparation would have a configuration of the form:
415
426
416
-
```clojure
417
-
{:paths ["src""target/classes"]
418
-
:deps/prep-lib {:alias :build
419
-
:fn compile
420
-
:ensure "target/classes"}}
421
-
```
427
+
!!! EXAMPLE
428
+
```clojure
429
+
{:paths["src" "target/classes"]
430
+
:deps/prep-lib {:alias:build
431
+
:fn compile
432
+
:ensure "target/classes"}}
433
+
```
422
434
423
435
Including the top-level key `:deps/prep-lib` tells the tools.deps classpath construction that something extra is needed to prepare this lib and that can be performed by invoking the compile function in the :build alias. Once the prepare step has been done, it should create the path "target/classes" and that can be checked for completion.
424
436
425
437
Add a library dependency as with any other library (git or local/root):
`:deps prep` will built the library of any dependency that requires it
434
447
435
-
```shell
436
-
clojure -X:deps prep
437
-
```
448
+
!!! NOTE ""
449
+
```shell
450
+
clojure -X:deps prep
451
+
```
438
452
439
453
## POM file
440
454
441
455
Generate or update pom.xml with deps and paths
442
456
443
-
```shell
444
-
clojure -X:deps mvn-pom
445
-
```
457
+
!!! NOTE ""
458
+
```shell
459
+
clojure -X:deps mvn-pom
460
+
```
446
461
447
462
448
463
## Resolve Git tags
@@ -451,9 +466,10 @@ clojure -X:deps mvn-pom
451
466
452
467
`-X:deps git-resolve-tags` updates git based dependencies in the project `deps.edn` file which use :git/tags key to the equivalent SHA commit values in the `:git/sha` key
Copy file name to clipboardExpand all lines: docs/clojure-cli/defining-aliases.md
+28-17Lines changed: 28 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,19 +26,22 @@ Aliases can be used to :
26
26
*`:mvn/local-repo` to [specify an alternative location for the Maven cache](https://github.com/practicalli/clojure-deps-edn#maven-local-repository)
27
27
*`:aliases` - a map of optional libraries and tools, the key being the alias name and its value the configuration
28
28
29
-
30
29
The installation of Clojure CLI contains a configuration
31
30
32
31
* adds `src` and `org.clojure/clojure` library
33
32
* Maven Central & Clojars.org repository sources.
34
33
35
-
Configuration can be defined in a `deps.edn` file in the root of a Clojure project, applying only to that specific project.
36
-
37
-
A user `deps.edn` configuration can be used in any Clojure project and the `deps.edn` configuration file resides in either `$XDG_CONFIG_HOME/clojure` or `$HOME/.clojure`.
34
+
Configuration available to all projects (or stand-alone tools) is defined in a user `deps.edn` configuration in either `$XDG_CONFIG_HOME/clojure` or `$HOME/.clojure`.
38
35
36
+
Project specific configuration is defined in a `deps.edn` file in the root of the Clojure project.
39
37
40
38
??? INFO "User configuration locations"
41
-
User configuration is either `$XDG_CONFIG_HOME/clojure/deps.edn` or `$HOME/.clojure/deps.edn` locations and its aliases can be used for any Clojure project.
39
+
If `XDG_CONFIG_HOME` environment variable is set, then the user configuration is `$XDG_CONFIG_HOME/clojure/deps.edn`
40
+
41
+
Otherwide the user configuration is `$HOME/.clojure/deps.edn`.
42
+
43
+
The `CLJ_CONFIG` environment variable will be used if set.
44
+
42
45
43
46
44
47
## Alias keys
@@ -118,7 +121,7 @@ Arguments can be nested within the `:exec-args` map, especially useful on projec
118
121
119
122
To run with the default arguments:
120
123
121
-
```
124
+
```shell
122
125
clojure -X:project/run
123
126
```
124
127
@@ -211,19 +214,27 @@ Additional arguments can be sent when running the command, e.g. `clojure -X:proj
211
214
212
215
The command line can over-ride the `:exec-fn` function configuration, allowing for a default configuration that can be easily over-ridden.
Legal Clojure keyword names can be used for an alias. Multiple aliases can be chained together with the `clojure` command. For example in this command we are combining three aliases:
226
-
`clojure -M:task/path:task/deps:build/options`
229
+
Alias names are a Clojure keyword, which can be qualified to provide context, e.g. `:project/create`.
230
+
231
+
Aliases are composable (chained together) and their path and deps configurations merged:
232
+
233
+
```shell
234
+
clojure -M:task/path:task/deps:build/options
235
+
```
236
+
237
+
When multiple aliases contain a `:main-opts` configurations they are not merged, the configuration in the last alias is used
Copy file name to clipboardExpand all lines: docs/clojure-cli/execution-options.md
+39-40Lines changed: 39 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,63 +2,48 @@
2
2
3
3
Execution options (`-A``-M``-P``-T``-X`) define how aliases are used with the Clojure CLI. Aliases are included via one of these execution options and each option can affect how the alias is used.
4
4
5
-
Since the [first documented released](https://clojure.org/releases/tools#v1.10.1.510) which exclusively used the `-A` execution option to include aliases, the design has evolved to provide specific execution options to run code via clojure.main (`-M`) and clojure.exec (`-X`). In July 2021, the ability to run tools (`-T`) independent from the Clojure project classpath was also introduced.
5
+
??? INFO "Clojure CLI design evolution"
6
+
The [first documented released](https://clojure.org/releases/tools#v1.10.1.510) used the `-A` execution option to include aliases.
6
7
7
-
The exec-opts command line flags have evolved to enable these features, so lets explore those flags and show how each flag is typically used.
8
+
The design has evolved to provide specific execution options to run code via clojure.main (`-M`) and clojure.exec (`-X`).
8
9
9
-
??? INFO "Understanding Aliases"
10
-
[Understand aliases in more detail](https://practical.li/blog/posts/clojure-cli-tools-understanding-aliases/)
10
+
In July 2021 the ability to run tools (`-T`) independent from the Clojure project classpath was introduced.
11
11
12
12
13
13
## Quick summary
14
14
15
-
Use `-M`for code that should be called via the `-main` function in a specified namespace, passing string-based arguments.
15
+
`-M`uses `clojure.main` to call the `-main` function of the specified namespace, passing string-based arguments.
16
16
17
-
Use `-X` to run a specified function, passing arguments as key and value pairs (not hash-maps yet)
17
+
`-X`uses `clojure.exec`to call a fully qualified function, passing arguments as key and value pairs
18
18
19
-
Use `-T`to run a tool independently from any libraries defined in a project. Only the libraries in the alias are included in the ClassPath. The path is defined as `"."` by default.
19
+
`-T`runs a tool independent from project dependencies. Only the libraries in the alias are included in the Class Path. The path is defined as `"."` by default.
20
20
21
-
Use `-P`to download libraries on the class path, including those from specified aliases
21
+
`-P`downloads library dependencies, including those from specified aliases
22
22
23
-
Use `-A` in the specific case of running a basic terminal UI REPL with the `clojure` command (or `clj` wrapper).
23
+
`-A` in the specific case of running a basic terminal UI REPL with the `clojure` command or `clj` wrapper.
24
24
25
-
Common aliases will be used to explain the use of these execution options in more detail.
26
25
26
+
## clojure.main
27
27
28
-
## Form of clojure.exec command line arguments
28
+
`-M` flag instructs Clojure CLI tools to use `clojure.main` to run Clojure code.
29
29
30
-
Clojure.exec command takes Key/value pairs read as EDN values (extensible data notation that is the base syntax of Clojure).
31
-
32
-
Number values and keywords can be parsed from the command line
33
-
34
-
Arguments that are vectors and hash maps should be wrapped in single quotes to avoid the command line shell splitting arguments at spaces, e.g. `'[:a :b]'`, `'{:c 1}'`.
35
-
36
-
The double quotes in an EDN string must be wrapped by single quotes, along with vectors and hash-maps
37
-
38
-
-`'"strings in double quotes surround by single quotes"'`
39
-
-`'[:vectors :with-single-quotes]'`
40
-
-`'{:hash-maps :with-single-quotes}'`
30
+
The `--main` or `-m` flag is an argument to `clojure.main` which specifies the namespace to search for a `-main` function.
41
31
32
+
`clojure.main/main` function searches for a `-main` function in the given namespace, e.g. `--main pracicalli.gameboard.service`
42
33
43
-
## Run clojure.main project
44
-
45
-
`-M` execution option uses `clojure.main` to run Clojure code.
34
+
> If the -main function is not found or the namespace is not specified, then the `clojure` command will run a REPL session.
46
35
47
36
Run a project with the main namespace `practicalli.sudoku-solver`, without any additional aliases on the command line
48
37
49
-
```shell
50
-
clojure -M -m practicalli.sudoku-solver
51
-
```
52
-
53
-
`-M` flag instructs Clojure CLI tools to use `clojure.main` to run the Clojure code.
54
-
55
-
`-m` flag is an argument to `clojure.main` which specifies the namespace to search for a `-main` function.
56
-
38
+
!!! NOTE ""
39
+
```shell
40
+
clojure -M -m practicalli.sudoku-solver
41
+
```
57
42
58
-
Adding a `:project/run` alias to the project `deps.edn` file provides a simpler way to run the project on the command line
43
+
Add `:project/run` alias to the project `deps.edn` file to provide a simpler way to run the project on the command line
Now the project code can be run using the simple command line form
@@ -68,13 +53,10 @@ clojure -M:project/run
68
53
```
69
54
70
55
71
-
### How clojure.main works
56
+
### Using clojure.main
72
57
73
-
`clojure.main/main` function searches for a `-main` function in the given namespace (`-m fully-qualified.namespace`)
74
58
75
-
If no -main function is found or the namespace is not specified, then a REPL session is run. This is the approach Leiningen has always used and still uses today.
76
-
77
-
> [`clojure.main` namespace](https://clojure.org/reference/repl_and_main) has been the way Clojure code was run (including a REPL) for most of its history. This is now evolving with the addition of [clojure.exec](#clojure-exec--X).
59
+
> [`clojure.main` namespace](https://clojure.org/reference/repl_and_main) has been the way Clojure code was run (including a REPL) for most of its history. This is now evolving with the addition of [clojure.exec](#clojureexec).
78
60
> [clojure.main has other features, as covered in the REPL and main entrypoints article](https://clojure.org/reference/repl_and_main)) on clojure.org.
79
61
80
62
@@ -137,6 +119,23 @@ If the command line includes the `-m` flag with a namespace, then that namespace
137
119
138
120
Any function on the class path can be called and is passed a hash-map as an argument. The argument hash-map is either specified in an alias using `:exec-args` or assembled into a hash-map from key/value pairs on the command line. Key/values from the command line are merged into the `:exec-args` map if it exists, with the command line key/values taking precedence.
139
121
122
+
### clojure.exec arguments
123
+
124
+
Clojure.exec command takes key value pairs read as EDN values (extensible data notation that is the base syntax of Clojure).
125
+
126
+
Number values and keywords can be parsed from the command line
127
+
128
+
Arguments that are vectors and hash maps should be wrapped in single quotes to avoid the command line shell splitting arguments at spaces, e.g. `'[:a :b]'`, `'{:c 1}'`.
129
+
130
+
The double quotes in an EDN string must be wrapped by single quotes, along with vectors and hash-maps
131
+
132
+
-`'"strings in double quotes surround by single quotes"'`
133
+
-`'[:vectors :with-single-quotes]'`
134
+
-`'{:hash-maps :with-single-quotes}'`
135
+
136
+
137
+
### clojure.exec examples
138
+
140
139
Call the `status` function from the namespace `practicalli.service`, which is on the classpath in the practicalli.service project
0 commit comments