improving errors for undefined options, and error messages for compile attempts on nonexistent files
This commit is contained in:
parent
213ae1430e
commit
c62f93f930
|
@ -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;
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: /\[(.+)\]/
|
||||
|
||||
|
|
Loading…
Reference in New Issue