Skip to content

Commit 2bcfd12

Browse files
fixes #29: CLI should reject unrecognised flags
1 parent b4391a7 commit 2bcfd12

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

lib/coffee-script/command.js

+12-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/command.coffee

+10-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ args = process.argv[1 + (process.argv[0] is 'node') ..]
2828

2929
# ignore args after --
3030
additionalArgs = []
31-
if '--' in args then additionalArgs = args.splice (args.indexOf '--'), 9e9
31+
if '--' in args then additionalArgs = (args.splice (args.indexOf '--'), 9e9)[1..]
3232

3333

3434
# initialise options
@@ -109,19 +109,23 @@ while args.length
109109
options[optionMap[match[2]]] = if match[1]? then off else on
110110
else if match = (reShortParameter.exec arg) ? reLongParameter.exec arg
111111
options[optionMap[match[1]]] = args.shift()
112+
else if match = /^(-.|--.*)$/.exec arg
113+
console.error "Unrecognised option '#{match[0].replace /'/g, '\\\''}'"
114+
process.exit 1
112115
else
113116
positionalArgs.push arg
114117

115118

116119
# input validation
117120

121+
positionalArgs = positionalArgs.concat additionalArgs
118122
unless options.compile or options.js or options.parse or options.eval or options.cscodegen
119123
if not escodegen?
120124
options.compile = on
121125
else if positionalArgs.length
122126
options.eval = on
123127
options.input = positionalArgs.shift()
124-
additionalArgs = [positionalArgs..., additionalArgs...]
128+
additionalArgs = positionalArgs
125129
else
126130
options.repl = on
127131

@@ -248,9 +252,10 @@ else
248252

249253
# preprocess
250254
if options.debug
251-
Preprocessor.processSync input
252-
console.error '### PREPROCESSED CS-AST ###'
253-
console.error numberLines humanReadable input.trim()
255+
try
256+
Preprocessor.processSync input
257+
console.error '### PREPROCESSED CS-AST ###'
258+
console.error numberLines humanReadable input.trim()
254259

255260
# parse
256261
result = CoffeeScript.parse input, optimise: no

0 commit comments

Comments
 (0)