Skip to content

Commit 6c48af3

Browse files
author
Danny McClanahan
committed
Add #! support for executable scripts on Linux.
Pass arguments to executable script unchanged if using "#!/usr/bin/env coffee". (Previously, "./test.coffee -abck" would be turned into "-a -b -c -k", for example.) Fixes jashkenas#1752.
1 parent 140a73d commit 6c48af3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/optparse.coffee

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{repeat} = require './helpers'
1+
{repeat, isCoffee} = require './helpers'
22

33
# A simple **OptionParser** class to parse option flags from the command-line.
44
# Use it like so:
@@ -25,6 +25,14 @@ exports.OptionParser = class OptionParser
2525
# parsers that allow you to attach callback actions for every flag. Instead,
2626
# you're responsible for interpreting the options object.
2727
parse: (args) ->
28+
# Pass all arguments to script unchanged if first argument is the script to
29+
# be run; assume no options are for the coffeescript compiler. This allows
30+
# the use of '#!/usr/bin/env coffee' to run executable scripts on Linux
31+
# systems, which do not parse the '--' argument in the first line correctly.
32+
if (args.indexOf '--' is -1) and
33+
(args.length > 0) and
34+
(isCoffee args[0])
35+
return arguments: args
2836
options = arguments: []
2937
skippingArgument = no
3038
originalArgs = args

0 commit comments

Comments
 (0)