Skip to content

Commit

Permalink
Add #! support for executable scripts on Linux.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Danny McClanahan committed Apr 16, 2015
1 parent 140a73d commit 6c48af3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/optparse.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{repeat} = require './helpers'
{repeat, isCoffee} = require './helpers'

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

0 comments on commit 6c48af3

Please sign in to comment.