-
Notifications
You must be signed in to change notification settings - Fork 2k
[CS2] Add #! support for executable scripts on Linux. #3946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
6c48af3
221dfc4
988f2af
fa3fe8b
aee066f
3c1fb7f
a10c653
d5e8d74
062fe62
c929ed9
b1acc4b
f3ea781
200126f
7970e44
bc92ff3
7e0d9e0
0a05e0c
3c49c8e
0e1f27e
42434b4
15eb624
bb9366c
e1bcf84
7bc6591
7c4723d
768ada6
79c0e56
ca7ad49
daa5f4d
c75e2b1
23f31c6
d495841
bafa82f
9247444
b509b46
31bbeb2
7abe19c
3944d94
f41463d
356f3ad
7c17e23
179687d
5b9b786
8448a77
14df734
b9291ae
f306859
4093574
4856fd6
f7e8c2b
6fb80c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
### Argument parsing and shebang lines | ||
|
||
#### Trailing `--` | ||
|
||
Previous versions of CoffeeScript required a `--` after the script to run, but this convention is now deprecated. The new standard is described in the output of `coffee -h`: | ||
|
||
``` bash | ||
> coffee -h | ||
|
||
Usage: coffee [options] [--] path/to/script.coffee [args] | ||
|
||
If called without options, `coffee` will run your script. | ||
|
||
|
||
``` | ||
|
||
If the script is run with a `--` after the script, it will show a warning, then run your script. | ||
|
||
``` bash | ||
> coffee path/to/script.coffee -- | ||
coffee was invoked with '--' as the second positional argument, which is | ||
now deprecated. To pass '--' as an argument to a script to run, put an | ||
additional '--' before the path to your script. | ||
|
||
'--' will be removed from the argument list. | ||
The positional arguments were: ["path/to/script.coffee","--"] | ||
... | ||
``` | ||
|
||
#### Shebang scripts | ||
|
||
On non-Windows platforms, a `.coffee` file can be made executable by adding a shebang (`#!`) line at the top of the file and marking the file as executable. For example: | ||
|
||
`executable-script.coffee`: | ||
``` coffeescript | ||
#!/usr/bin/env coffee | ||
|
||
x = 2 + 2 | ||
console.log x | ||
``` | ||
|
||
``` bash | ||
> chmod +x ./executable-script.coffee | ||
> ./executable-script.coffee | ||
4 | ||
``` | ||
|
||
Due to a bug in the argument parsing of previous CoffeeScript versions, this used to fail when trying to pass arguments to the script. Some users on OSX worked around the problem by using `#!/usr/bin/env coffee --` at the top of the file instead. However, that won't work on Linux, which cannot parse shebang lines with more than a single argument. While these scripts will still run on OSX, CoffeeScript will now display a warning before compiling or evaluating files that begin with a too-long shebang line: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It’s “OS X”. Also the documentation uses curly quotes, e.g. “won’t”. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed both of those. |
||
|
||
`invalid-executable-script.coffee`: | ||
``` coffeescript | ||
#!/usr/bin/env coffee -- | ||
|
||
x = 2 + 2 | ||
console.log x | ||
``` | ||
|
||
``` bash | ||
> chmod +x /path/to/invalid-executable-script.coffee | ||
> /path/to/invalid-executable-script.coffee | ||
The script to be run begins with a shebang line with more than one | ||
argument. This script will fail on platforms such as Linux which only | ||
allow a single argument. | ||
The shebang line was: '#!/usr/bin/env coffee --' in file '/path/to/shebang-extra-args.coffee' | ||
The arguments were: ["coffee","--"] | ||
4 | ||
``` | ||
|
||
Note that the script *is* still run, producing the `4` at the bottom. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the blank lines before and after the text?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually screwed up the help text (see the most recent commit -- needed to change the help method to use
@rules.ruleList
instead of just@rules
). I made that fix, changed this text, and have also added tests intest/option_parser.coffee
in the most recent commit to ensure the help text will always display the banner and the flags.