Skip to content

Commit f43047f

Browse files
committed
Fix #5986 Improve documentation of stack script
1 parent 9b1fa15 commit f43047f

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

doc/script_command.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,27 @@ stack script [--package PACKAGE] FILE
99
[--extra-dep PACKAGE-VERSION] [--no-run]
1010
~~~
1111

12-
The `stack script` command also either runs a specified Haskell source file
13-
(using GHC's `runghc`) or, optionally, compiles a specified Haskell source file
14-
(using GHC) and, by default, runs it.
12+
The `stack script` command either runs a specified Haskell source file (using
13+
GHC's `runghc`) or, optionally, compiles a specified Haskell source file (using
14+
GHC) and, by default, runs it.
1515

16-
However, unlike `stack ghc` and `stack runghc`, the command ignores all Stack
17-
YAML configuration files. A snapshot must be specified on the command line (with
18-
the `--resolver` option). For example:
16+
Unlike `stack ghc` and `stack runghc`, the command ignores all Stack YAML
17+
configuration files (global and project-level). A snapshot must be specified on
18+
the command line (with the `--resolver` option). For example:
1919

2020
~~~text
21-
stack --resolver lts-19.28 MyScript.hs
21+
stack --resolver lts-20.4 MyScript.hs
2222
~~~
2323

2424
or, equivalently:
2525

2626
~~~text
27-
stack script --resolver lts-19.28 MyScript.hs
27+
stack script --resolver lts-20.4 MyScript.hs
2828
~~~
2929

30+
The `stack script` command behaves as if the `--install-ghc` flag had been
31+
passed at the command line.
32+
3033
Everything after `--` on the command line is interpreted as a command line
3134
argument to be passed to what is run.
3235

@@ -69,5 +72,5 @@ main = do
6972
can be compiled and run, with arguments, with:
7073

7174
~~~text
72-
stack --resolver lts-19.28 script --package acme-missiles --compile MyScript.hs -- "Don't panic!" "Duck and cover!"
75+
stack --resolver lts-20.4 script --package acme-missiles --compile MyScript.hs -- "Don't panic!" "Duck and cover!"
7376
~~~

doc/scripts.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
# Stack's script interpreter
44

5-
Stack also offers a very useful feature for running files: a script interpreter.
6-
For too long have Haskellers felt shackled to bash or Python because it's just
7-
too hard to create reusable source-only Haskell scripts. Stack attempts to solve
5+
Stack offers a very useful feature for running files: a script interpreter. For
6+
too long have Haskellers felt shackled to bash or Python because it's just too
7+
hard to create reusable source-only Haskell scripts. Stack attempts to solve
88
that.
99

1010
You can use `stack <file_name>` to execute a Haskell source file. Usually, the
@@ -19,7 +19,7 @@ An example will be easiest to understand. Consider the Haskell source file
1919

2020
~~~haskell
2121
#!/usr/bin/env stack
22-
-- stack script --resolver lts-19.28 --package turtle
22+
-- stack script --resolver lts-20.4 --package turtle
2323
{-# LANGUAGE OverloadedStrings #-}
2424
import Turtle (echo)
2525
main = echo "Hello World!"
@@ -78,10 +78,10 @@ able to reuse everything already built).
7878

7979
The second line of the source code is the Stack interpreter options comment. In
8080
this example, it specifies the `stack script` command with the options of a
81-
LTS Haskell 19.28 snapshot (`--resolver lts-19.28`) and ensuring the
81+
LTS Haskell 20.4 snapshot (`--resolver lts-20.4`) and ensuring the
8282
[`turtle` package](https://hackage.haskell.org/package/turtle) is available
8383
(`--package turtle`). The version of the package will be that in the specified
84-
snapshot (`lts-19.28` provides `turtle-1.5.25`).
84+
snapshot (`lts-20.4` provides `turtle-1.5.25`).
8585

8686
## Arguments and interpreter options and arguments
8787

@@ -116,7 +116,7 @@ For example, the command `stack MyScript.hs arg1 arg2` with `MyScript.hs`:
116116
~~~haskell
117117
#!/usr/bin/env stack
118118
{- stack script
119-
--resolver lts-19.28
119+
--resolver lts-20.4
120120
--
121121
+RTS -s -RTS
122122
-}
@@ -132,7 +132,7 @@ main = do
132132
is equivalent to the following command at the command line:
133133

134134
~~~text
135-
stack script --resolver lts-19.28 -- MyScript.hs arg1 arg2 +RTS -s -RTS
135+
stack script --resolver lts-20.4 -- MyScript.hs arg1 arg2 +RTS -s -RTS
136136
~~~
137137

138138
where `+RTS -s -RTS` are some of GHC's
@@ -161,7 +161,7 @@ space separated list. For example:
161161
~~~haskell
162162
#!/usr/bin/env stack
163163
{- stack script
164-
--resolver lts-19.28
164+
--resolver lts-20.4
165165
--package turtle
166166
--package "stm async"
167167
--package http-client,http-conduit
@@ -170,7 +170,8 @@ space separated list. For example:
170170

171171
## Stack configuration for scripts
172172

173-
With the `stack script` command, all Stack YAML configuration files are ignored.
173+
With the `stack script` command, all Stack YAML configuration files (global and
174+
project-level) are ignored.
174175

175176
With the `stack runghc` command, if the current working directory is inside a
176177
project then that project's Stack project-level YAML configuration is effective
@@ -190,7 +191,7 @@ which makes use of the joke package
190191

191192
~~~haskell
192193
{- stack script
193-
--resolver lts-19.28
194+
--resolver lts-20.4
194195
--package acme-missiles
195196
-}
196197
import Acme.Missiles (launchMissiles)
@@ -201,16 +202,17 @@ main = launchMissiles
201202

202203
The command `stack --script-no-run-compile Script.hs` then behaves as if the
203204
command
204-
`stack script --resolver lts-19.28 --package acme-missiles --no-run --compile -- Script.hs`
205+
`stack script --resolver lts-20.4 --package acme-missiles --no-run --compile -- Script.hs`
205206
had been given. `Script.hs` is compiled (without optimisation) and the resulting
206207
executable is not run: no missiles are launched in the process!
207208

208209
## Writing independent and reliable scripts
209210

210211
The `stack script` command will automatically:
211212

212-
* Install GHC and libraries if missing
213-
* Require that all packages used be explicitly stated on the command line
213+
* Install GHC and libraries, if missing. `stack script` behaves as if the
214+
`--install-ghc` flag had been passed at the command line.
215+
* Require that all packages used be explicitly stated on the command line.
214216

215217
This ensures that your scripts are _independent_ of any prior deployment
216218
specific configuration, and are _reliable_ by using exactly the same version of
@@ -237,7 +239,7 @@ example with `runghc`:
237239
{- stack
238240
runghc
239241
--install-ghc
240-
--resolver lts-19.17
242+
--resolver lts-20.4
241243
--package base
242244
--package turtle
243245
--
@@ -260,7 +262,7 @@ it. Here is an example:
260262
{- stack
261263
exec ghci
262264
--install-ghc
263-
--resolver lts-19.28
265+
--resolver lts-20.4
264266
--package turtle
265267
-}
266268
~~~

0 commit comments

Comments
 (0)