Skip to content

Commit

Permalink
Merge pull request #108 from davidchambers/sanctuary-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchambers authored Mar 5, 2019
2 parents 7b2414d + 190e2e6 commit c9b180a
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 211 deletions.
50 changes: 28 additions & 22 deletions lib/command.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,58 @@
'use strict';

var program = require('commander');
var program = require ('commander');

var doctest = require('..');
var pkg = require('../package.json');
var doctest = require ('..');
var pkg = require ('../package.json');


program
.version(pkg.version)
.usage('[options] path/to/js/or/coffee/module')
.option('-m, --module <type>', 'specify module system ("amd" or "commonjs")')
.option(' --nodejs <options>', 'pass options directly to the "node" binary')
.option(' --prefix <prefix>', 'specify Transcribe-style prefix (e.g. ".")')
.option('-p, --print', 'output the rewritten source without running tests')
.option('-s, --silent', 'suppress output')
.option('-t, --type <type>', 'specify file type ("coffee" or "js")')
.parse(process.argv);
.version (pkg.version)
.usage ('[options] path/to/js/or/coffee/module')
.option ('-m, --module <type>',
'specify module system ("amd" or "commonjs")')
.option (' --nodejs <options>',
'pass options directly to the "node" binary')
.option (' --prefix <prefix>',
'specify Transcribe-style prefix (e.g. ".")')
.option ('-p, --print',
'output the rewritten source without running tests')
.option ('-s, --silent',
'suppress output')
.option ('-t, --type <type>',
'specify file type ("coffee" or "js")')
.parse (process.argv);

// formatErrors :: Array String -> String
function formatErrors(errors) {
return errors.map(function(s) { return 'error: ' + s + '\n'; }).join('');
return (errors.map (function(s) { return 'error: ' + s + '\n'; })).join ('');
}

var errors = [];
if (program.module != null &&
program.module !== 'amd' &&
program.module !== 'commonjs') {
errors.push('Invalid module `' + program.module + "'");
errors.push ('Invalid module `' + program.module + "'");
}
if (program.type != null &&
program.type !== 'coffee' &&
program.type !== 'js') {
errors.push('Invalid type `' + program.type + "'");
errors.push ('Invalid type `' + program.type + "'");
}
if (errors.length > 0) {
process.stderr.write(formatErrors(errors));
process.exit(1);
process.stderr.write (formatErrors (errors));
process.exit (1);
}

process.exit(program.args.reduce(function(status, path) {
process.exit (program.args.reduce (function(status, path) {
var results;
try {
results = doctest(path, program);
results = doctest (path, program);
} catch (err) {
process.stderr.write(formatErrors([err.message]));
process.exit(1);
process.stderr.write (formatErrors ([err.message]));
process.exit (1);
}
return results.reduce(function(status, tuple) {
return results.reduce (function(status, tuple) {
return tuple[0] ? status : 1;
}, status);
}, 0));
Loading

0 comments on commit c9b180a

Please sign in to comment.