Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test (see #52) #96

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,41 @@
node_modules
### https://raw.github.com/github/gitignore/9779d87d3d81ffacd90ae2470e7b3ffe566ffc71/node.gitignore

# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history


3 changes: 3 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test:
override:
- npm run test
38 changes: 19 additions & 19 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ for (var module in natives) {
define_native(module);
}

cli.output = console.log;
cli.output = console.error;
cli.exit = require('exit');

cli.no_color = false;
Expand Down Expand Up @@ -333,7 +333,7 @@ cli.parse = function (opts, command_def) {
if (cli.version == null) {
cli.parsePackageJson();
}
console.error(cli.app + ' v' + cli.version);
cli.output(cli.app + ' v' + cli.version);
cli.exit();
break;
} else if (enable.catchall && (o === 'c' || o === 'catch')) {
Expand Down Expand Up @@ -453,13 +453,13 @@ cli.status = function (msg, type) {
}
msg = pre + ' ' + msg;
if (type === 'fatal') {
console.error(msg);
cli.output(msg);
return cli.exit(1);
}
if (enable.status && !show_debug && type === 'debug') {
return;
}
console.error(msg);
cli.output(msg);
};
['info','error','ok','debug','fatal'].forEach(function (type) {
cli[type] = function (msg) {
Expand Down Expand Up @@ -582,11 +582,11 @@ cli.getUsage = function (code) {

usage = usage || cli.app + ' [OPTIONS]' + (command_list.length ? ' <command>' : '') + ' [ARGS]';
if (cli.no_color) {
console.error('Usage:\n ' + usage);
console.error('Options: ');
cli.output('Usage:\n ' + usage);
cli.output('Options: ');
} else {
console.error('\x1b[1mUsage\x1b[0m:\n ' + usage);
console.error('\n\x1b[1mOptions\x1b[0m: ');
cli.output('\x1b[1mUsage\x1b[0m:\n ' + usage);
cli.output('\n\x1b[1mOptions\x1b[0m: ');
}
for (var opt in opt_list) {

Expand Down Expand Up @@ -634,42 +634,42 @@ cli.getUsage = function (code) {
line = pad(line, switch_pad);
line += trunc_desc(line, desc);
line += optional ? ' (Default is ' + optional + ')' : '';
console.error(line.replace('%s', '%\0s'));
cli.output(line.replace('%s', '%\0s'));

seen_opts.push(short);
seen_opts.push(long);
}
if (enable.timeout && seen_opts.indexOf('t') === -1 && seen_opts.indexOf('timeout') === -1) {
console.error(pad(' -t, --timeout N', switch_pad) + 'Exit if the process takes longer than N seconds');
cli.output(pad(' -t, --timeout N', switch_pad) + 'Exit if the process takes longer than N seconds');
}
if (enable.status) {
if (seen_opts.indexOf('k') === -1 && seen_opts.indexOf('no-color') === -1) {
console.error(pad(' -k, --no-color', switch_pad) + 'Omit color from output');
cli.output(pad(' -k, --no-color', switch_pad) + 'Omit color from output');
}
if (seen_opts.indexOf('debug') === -1) {
console.error(pad(' --debug', switch_pad) + 'Show debug information');
cli.output(pad(' --debug', switch_pad) + 'Show debug information');
}
}
if (enable.catchall && seen_opts.indexOf('c') === -1 && seen_opts.indexOf('catch') === -1) {
console.error(pad(' -c, --catch', switch_pad) + 'Catch unanticipated errors');
cli.output(pad(' -c, --catch', switch_pad) + 'Catch unanticipated errors');
}
if (enable.version && seen_opts.indexOf('v') === -1 && seen_opts.indexOf('version') === -1) {
console.error(pad(' -v, --version', switch_pad) + 'Display the current version');
cli.output(pad(' -v, --version', switch_pad) + 'Display the current version');
}
if (enable.help && seen_opts.indexOf('h') === -1 && seen_opts.indexOf('help') === -1) {
console.error(pad(' -h, --help', switch_pad) + 'Display help and usage details');
cli.output(pad(' -h, --help', switch_pad) + 'Display help and usage details');
}
if (command_list.length) {
console.error('\n\x1b[1mCommands\x1b[0m: ');
cli.output('\n\x1b[1mCommands\x1b[0m: ');
if (!Array.isArray(commands)) {
for (var c in commands) {
line = ' ' + pad(c, switch_pad - 2);
line += trunc_desc(line, commands[c]);
console.error(line);
cli.output(line);
}
} else {
command_list.sort();
console.error(' ' + trunc_desc(' ', command_list.join(', ')));
cli.output(' ' + trunc_desc(' ', command_list.join(', ')));
}
}
return cli.exit(code);
Expand Down Expand Up @@ -970,7 +970,7 @@ cli.main = function (callback) {
cli.createServer = function(/*layers*/) {
var defaultStackErrorHandler = function (req, res, err) {
if (err) {
console.error(err.stack);
cli.output(err.stack);
res.writeHead(500, {"Content-Type": "text/plain"});
return res.end(err.stack + "\n");
}
Expand Down
9 changes: 9 additions & 0 deletions package.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
"glob": "^7.1.1",
"exit": "0.1.2"
},
"devDependencies": {
"intelli-espower-loader": "^1.0.1",
"mocha": "^3.2.0",
"power-assert": "^1.4.2",
"proxyquire": "^1.7.11"
},
"scripts": {
"test": "mocha --require intelli-espower-loader"
},
"contributors": [
{ "name": "Douglas Meyer", "github": "https://github.com/DouglasMeyer" }
],
Expand Down
Loading