Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
This module implements parsing of additional arguments embedded in a comment when Stack is invoked as a script interpreter
Specifying arguments in script interpreter mode
stack
can execute a Haskell source file using runghc
and if required
it can also install and setup the compiler and any package dependencies
automatically.
For using a Haskell source file as an executable script on a Unix like OS,
the first line of the file must specify stack
as the interpreter using a
shebang directive e.g.
#!/usr/bin/env stack
Additional arguments can be specified in a haskell comment following the
#!
line. The contents inside the comment must be a single valid stack
command line, starting with stack
as the command and followed by the
options to use for executing this file.
The comment must be on the line immediately following the #!
line. The
comment must start in the first column of the line. When using a block style
comment the command can be split on multiple lines.
Here is an example of a single line comment:
#!/usr/bin/env stack -- stack --resolver lts-3.14 --install-ghc runghc --package random
Here is an example of a multi line block comment:
#!/usr/bin/env stack {- stack --resolver lts-3.14 --install-ghc runghc --package random -}
When the #!
line is not present, the file can still be executed
using stack <file name>
command if the file starts with a valid stack
interpreter comment. This can be used to execute the file on Windows for
example.
Nested block comments are not supported.
Synopsis
- interpreterArgsParser :: Bool -> String -> Parser String
- getInterpreterArgs :: String -> IO [String]