@ -20,6 +20,7 @@ that is appreciated by most Go programmers, see for example the following
### Table of contents
### Table of contents
- [Quick start ](#quick-start )
- [Installation ](#installation )
- [Installation ](#installation )
- [Usage ](#usage )
- [Usage ](#usage )
- [CLI ](#cli )
- [CLI ](#cli )
@ -33,6 +34,31 @@ that is appreciated by most Go programmers, see for example the following
- [Version policy ](#version-policy )
- [Version policy ](#version-policy )
- [Formatting specification ](#formatting-specification )
- [Formatting specification ](#formatting-specification )
## Quick start
Copy-pasteable setup commands for the impatient:
```sh
# Install Runic
julia --project=@runic -e 'using Pkg; Pkg.add("Runic")'
# Install the runic shell script
curl -fsSL -o ~/.local/bin/runic https://raw.githubusercontent.com/fredrikekre/Runic.jl/refs/heads/master/bin/runic
chmod +x ~/.local/bin/runic
```
Assuming `~/.local/bin` is in your `PATH` you can now invoke `runic` , e.g.:
```sh
runic --version # Show version info
runic --help # Show documentation
```
```sh
# Format all files in-place in the current directory (recursively)
# !! DON'T DO THIS FROM YOUR HOME DIRECTORY !!
runic --inplace .
```
## Installation
## Installation
Runic can be installed with Julia's package manager:
Runic can be installed with Julia's package manager:
@ -48,34 +74,69 @@ Runic in a separate project such as e.g. the shared project `@runic`:
julia --project=@runic -e 'using Pkg; Pkg.add("Runic")'
julia --project=@runic -e 'using Pkg; Pkg.add("Runic")'
```
```
## Usage
The main interface to Runic is the command line interface (CLI) through the `main` function:
### CLI
The main interface to Runic is the command line interface (CLI) through the `main` function
```sh
invoked with the `-m` flag. See the output of `julia -m Runic --help` below for usage
julia --project=@runic -e 'using Runic; exit(Runic.main(ARGS))' -- < args >
details.
```
The following snippet can be added to your shell startup file so that the CLI can be invoked
To simplify the invocation of the CLI it is recommended to install the
a bit more ergonomically. This assumes Runic is installed in the `@runic` shared project as
[`runic` ](https://github.com/fredrikekre/Runic.jl/blob/master/bin/runic ) shell script into a
suggested in the [Installation ](#installation ) section above. Adjust the `--project` flag if
directory in your `PATH` . This can be done with the following commands (replace the two
you installed Runic elsewhere.
occurences of `~/.local/bin` if needed):
```sh
```sh
alias runic="julia --project=@runic -m Runic"
# Download the script into ~/.local/bin
curl -fsSL -o ~/.local/bin/runic https://raw.githubusercontent.com/fredrikekre/Runic.jl/refs/heads/master/bin/runic
# Make the script executable
chmod +x ~/.local/bin/runic
# Verify the installation
runic --version
```
```
> [!NOTE]
> [!NOTE]
> The `-m` command line flag is only available in Julia 1.12 and later. In earlier versions
> Alternatively you can can add a shell alias to your shell startup file. The drawback of
> you have to invoke the `main` function explicitly, for example:
> this approach is that runic can only be invoked from the shell and not by other programs.
> ```sh
> ```sh
> julia -e 'using Runic; exit(Runic.main(ARGS))' -- < args >
> alias runic="julia --project=@runic -e 'using Runic; exit(Runic.main(ARGS))' --"
> # alias runic="julia --project=@runic -m Runic"
> ```
> ```
> For this incantation the following shell alias can be used:
> [!NOTE]
> In Julia 1.12 and later the `main` function can be invoked with the `-m` flag, i.e.:
> ```sh
> ```sh
> alias runic="julia --project=@runic -e 'using Runic; exit(Runic.main(ARGS))' --"
> julia --project=@runic -m Runic < args >
> ```
> ```
## Usage
### CLI
The CLI is the main interface to Runic. `runic --help` will show all available options
(output included below). Some example invokations are listed here.
Format a single file in place:
```sh
runic --inplace file.jl
```
Format all files in a directory (recursively) in place:
```sh
runic --inplace src/
```
Verify formatting of all files in a directory with verbose and diff output:
```sh
runic --check --diff --verbose src/
```
Format the content of standard in and print the result to standard out:
```sh
echo "1+1" | runic
```
Output of `runic --help` for a complete list of options:
```
```
$ runic --help
$ runic --help
NAME
NAME