Skip to content

Commit ff42fb2

Browse files
authored
Update README.md
1 parent afd521c commit ff42fb2

File tree

1 file changed

+22
-32
lines changed

1 file changed

+22
-32
lines changed

docs/README.md

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
- [Installation](#installation)
2+
- [Usage](#usage)
3+
- [Scripts](#scripts)
4+
- [Executable Scripts](#executable-scripts)
5+
- [Expressions](#expressions)
6+
- [Filters](#filters)
7+
- [Environment Variables](#environment-variables)
8+
- [Templates](#templates)
9+
- [Troubleshooting](#troubleshooting)
10+
11+
<a name="overview"></a>
12+
## Overview
13+
114
Some of `rust-script`'s features include:
215

316
- Reading Cargo manifests embedded in Rust scripts.
@@ -8,19 +21,8 @@ Some of `rust-script`'s features include:
821
- Running unit tests and benchmarks from scripts.
922
- Custom templates for command-line expressions and filters.
1023

11-
Table of contents:
12-
13-
- [Installation](#installation)
14-
- [Usage](#usage)
15-
- [Scripts](#scripts)
16-
- [Executable Scripts](#shebang)
17-
- [Expressions](#expressions)
18-
- [Stream Filters](#filters)
19-
- [Environment Variables](#env-vars)
20-
- [Templates](#templates)
21-
- [Troubleshooting](#troubleshooting)
24+
Generally, you can get an overview of the available options using the `--help` flag.
2225

23-
<a name="installation"></a>
2426
## Installation
2527

2628
Install or update `rust-script` using Cargo:
@@ -31,13 +33,7 @@ cargo install --force rust-script
3133

3234
The latest stable version of Rust (1.47.0) is required.
3335

34-
<a name="usage"></a>
35-
## Usage
36-
37-
Generally, you can get an overview of the available options using the `--help` flag.
38-
39-
<a name="scripts"></a>
40-
### Scripts
36+
## Scripts
4137

4238
The primary use for `rust-script` is for running Rust source files as scripts. For example:
4339

@@ -105,8 +101,7 @@ Useful command-line arguments:
105101
- `--gen-pkg-only`: Generate the Cargo package, but don't compile or run it. Effectively "unpacks" the script into a Cargo package.
106102
- `--test`: Compile and run tests.
107103

108-
<a name="shebang"></a>
109-
### Executable Scripts
104+
## Executable Scripts
110105

111106
On Unix systems, you can use `#!/usr/bin/env rust-script` as a shebang line in a Rust script. This will allow you to execute a script file directly.
112107

@@ -118,8 +113,7 @@ Uninstall the file association with `rust-script --uninstall-file-association`.
118113

119114
If you want to make a script usable across platforms, use *both* a hashbang line *and* give the file a `.crs` file extension.
120115

121-
<a name="expressions"></a>
122-
### Expressions
116+
## Expressions
123117

124118
`rust-script` can also run pieces of Rust code directly from the command line. This is done by providing the `--expr` option; this causes `rust-script` to interpret the `<script>` argument as source code *instead* of as a file path. For example, code can be executed from the command line in a number of ways:
125119

@@ -137,10 +131,9 @@ Useful command-line arguments:
137131
- `-D`/`--dep-extern`: do both of the above.
138132
- `-t`/`--template`: Specify a custom template for this expression (see section on templates).
139133

140-
<a name="filters"></a>
141-
### Stream Filters
134+
## Filters
142135

143-
You can use `rust-script` to write a quick stream filter, by specifying a closure to be called for each line read from stdin, like so:
136+
You can use `rust-script` to write a quick filter, by specifying a closure to be called for each line read from stdin, like so:
144137

145138
```sh
146139
$ cat now.crs | rust-script --loop \
@@ -168,8 +161,7 @@ $ cat now.crs | rust-script --count --loop \
168161
169162
Note that, like with expressions, you can specify a custom template for stream filters.
170163
171-
<a name="env-vars"></a>
172-
### Environment Variables
164+
## Environment Variables
173165
174166
The following environment variables are provided to scripts by `rust-script`:
175167
@@ -181,8 +173,7 @@ The following environment variables are provided to scripts by `rust-script`:
181173
182174
- `CARGO_SCRIPT_SCRIPT_PATH`: absolute path to the script being run, assuming one exists. Set to the empty string for expressions.
183175
184-
<a name="templates"></a>
185-
### Templates
176+
## Templates
186177
187178
You can use templates to avoid having to re-specify common code and dependencies. You can view a list of your templates by running `rust-script templates list` (note the hyphen), or show the folder in which they should be stored by running `rust-script templates show`. You can dump the contents of a template using `rust-script templates dump NAME`.
188179
@@ -216,8 +207,7 @@ $ rust-script -t grabbag -e "mem::size_of::<Box<Read>>()"
216207
217208
In addition, there are three built-in templates: `expr`, `loop`, and `loop-count`. These are used for the `--expr`, `--loop`, and `--loop --count` invocation forms. They can be overridden by placing templates with the same name in the template folder. If you have *not* overridden them, you can dump the contents of these built-in templates using the `templates dump` command noted above.
218209
219-
<a name="troubleshooting"></a>
220-
### Troubleshooting
210+
## Troubleshooting
221211
222212
Please report all issues on [the GitHub issue tracker](https://github.com/fornwall/rust-script/issues).
223213

0 commit comments

Comments
 (0)