diff --git a/lib/command_line.js b/lib/command_line.js index 562e0ad9..0d971eb3 100644 --- a/lib/command_line.js +++ b/lib/command_line.js @@ -59,8 +59,13 @@ compile_scripts = function compile_scripts() { var _a, _b, _c, compile, source; compile = function compile(source) { - return fs.readFile(source, function(err, code) { - return compile_script(source, code); + return path.exists(source, function(exists) { + if (!(exists)) { + throw new Error('File not found: ' + source); + } + return fs.readFile(source, function(err, code) { + return compile_script(source, code); + }); }); }; _a = []; _b = sources; diff --git a/lib/optparse.js b/lib/optparse.js index c6bd6b73..14d4027d 100755 --- a/lib/optparse.js +++ b/lib/optparse.js @@ -19,13 +19,12 @@ }; args = args.slice(0); while (arg = args.shift()) { - is_option = false; + is_option = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG)); _a = this.rules; for (_b = 0; _b < _a.length; _b++) { rule = _a[_b]; if (rule.letter === arg || rule.flag === arg) { options[rule.name] = rule.has_argument ? args.shift() : true; - is_option = true; break; } } @@ -56,7 +55,7 @@ return lines.join('\n'); }; // Regex matchers for option flags. - LONG_FLAG = /^(--[\w\-]+)/; + LONG_FLAG = /^(--\w[\w\-]+)/; SHORT_FLAG = /^(-\w+)/; OPTIONAL = /\[(.+)\]/; // Build rules from a list of valid switch tuples in the form: diff --git a/src/command_line.coffee b/src/command_line.coffee index 5ed9e5d2..06fca5d7 100644 --- a/src/command_line.coffee +++ b/src/command_line.coffee @@ -63,7 +63,9 @@ version: -> # or JSLint results. compile_scripts: -> compile: (source) -> - fs.readFile source, (err, code) -> compile_script(source, code) + path.exists source, (exists) -> + throw new Error 'File not found: ' + source unless exists + fs.readFile source, (err, code) -> compile_script(source, code) compile(source) for source in sources # Compile a single source script, containing the given code, according to the diff --git a/src/optparse.coffee b/src/optparse.coffee index 43ef628d..3e2c588e 100644 --- a/src/optparse.coffee +++ b/src/optparse.coffee @@ -13,11 +13,10 @@ op::parse: (args) -> options: {arguments: []} args: args.slice 0 while arg: args.shift() - is_option: false + is_option: !!(arg.match(LONG_FLAG) or arg.match(SHORT_FLAG)) for rule in @rules if rule.letter is arg or rule.flag is arg options[rule.name]: if rule.has_argument then args.shift() else true - is_option: true break options.arguments.push arg unless is_option options @@ -33,7 +32,7 @@ op::help: -> lines.join('\n') # Regex matchers for option flags. -LONG_FLAG: /^(--[\w\-]+)/ +LONG_FLAG: /^(--\w[\w\-]+)/ SHORT_FLAG: /^(-\w+)/ OPTIONAL: /\[(.+)\]/