-
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 1 commit
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 |
---|---|---|
|
@@ -11,6 +11,25 @@ Usage: coffee [options] [--] path/to/script.coffee [args] | |
|
||
If called without options, `coffee` will run your script. | ||
|
||
-b, --bare compile without a top-level function wrapper | ||
-c, --compile compile to JavaScript and save as .js files | ||
-e, --eval pass a string from the command line as input | ||
-h, --help display this help message | ||
-i, --interactive run an interactive CoffeeScript REPL | ||
-j, --join concatenate the source CoffeeScript before compiling | ||
-m, --map generate source map and save as .js.map files | ||
-M, --inline-map generate source map and include it directly in output | ||
-n, --nodes print out the parse tree that the parser produces | ||
--nodejs pass options directly to the "node" binary | ||
--no-header suppress the "Generated by" header | ||
-o, --output set the output directory for compiled JavaScript | ||
-p, --print print out the compiled JavaScript | ||
-r, --require require the given module before eval or REPL | ||
-s, --stdio listen for and compile scripts over stdio | ||
-l, --literate treat stdio as literate style coffeescript | ||
-t, --tokens print out the tokens that the lexer/rewriter produce | ||
-v, --version display the version number | ||
-w, --watch watch scripts for changes and rerun commands | ||
|
||
``` | ||
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. Why the blank lines before and after the text? 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. I actually screwed up the help text (see the most recent commit -- needed to change the help method to use |
||
|
||
|
@@ -45,7 +64,7 @@ console.log x | |
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: | ||
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 OS X 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. Another “OS X”. 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. |
||
|
||
`invalid-executable-script.coffee`: | ||
``` coffeescript | ||
|
@@ -61,7 +80,7 @@ console.log x | |
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 shebang line was: '#!/usr/bin/env coffee --' in file '/path/to/invalid-executable-script.coffee' | ||
The arguments were: ["coffee","--"] | ||
4 | ||
``` | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,18 @@ | |
return unless require? | ||
{OptionParser} = require './../lib/coffeescript/optparse' | ||
|
||
opt = new OptionParser [ | ||
flags = [ | ||
['-r', '--required [DIR]', 'desc required'] | ||
['-o', '--optional', 'desc optional'] | ||
['-l', '--list [FILES*]', 'desc list'] | ||
] | ||
|
||
banner = ''' | ||
banner text | ||
''' | ||
|
||
opt = new OptionParser flags, banner | ||
|
||
test "basic arguments", -> | ||
args = ['one', 'two', 'three', '-r', 'dir'] | ||
result = opt.parse args | ||
|
@@ -65,3 +71,37 @@ test "throw if multiple flags try to use the same short or long name", -> | |
['--just-long', 'desc'] | ||
['-j', '--just-long', 'another desc'] | ||
] | ||
|
||
reQuote = (str) -> (str ? '').replace /[.?*+^$[\]\\(){}|-]/g, "\\$&" | ||
|
||
flagPattern = (flag) -> | ||
switch flag.length | ||
when 2 | ||
shortFlag = null | ||
[longFlag, desc] = flag | ||
when 3 | ||
[shortFlag, longFlag, desc] = flag | ||
else | ||
throw new Error "invalid flag" | ||
longFlagPat = reQuote longFlag.match(/--[^\s]+/)[0] | ||
descPat = reQuote desc | ||
if shortFlag? | ||
joined = [reQuote(shortFlag), longFlagPat, descPat].join '.*' | ||
else | ||
joined = [longFlagPat, descPat].join '.*' | ||
new RegExp "^.*#{joined}.*$", 'm' | ||
|
||
test "help text shows banner and all switches", -> | ||
bannerHelp = opt.help() | ||
bannerPattern = new RegExp reQuote(banner), 'g' | ||
ok bannerHelp.match bannerPattern | ||
for flag in flags | ||
linePat = flagPattern flag | ||
ok bannerHelp.match linePat | ||
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. This tests that the option parser correctly outputs a banner text string, but not necessarily that 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. Ok, that makes sense. I'll make that change. |
||
|
||
test "help text shows switches, even without banner", -> | ||
parser = new OptionParser flags | ||
noBannerHelp = parser.help() | ||
for flag in flags | ||
linePat = flagPattern flag | ||
ok noBannerHelp.match linePat |
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.
This is already documented in http://coffeescript.org/v2/#usage. The Breaking Changes section should only discuss breaking changes from 1.x.
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.
That makes sense. I have noted only the changed usage line now and left an
...
to denote the rest of the help text.