Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed a bug with commands parsing

  • Loading branch information...
commit ffb348f50bf692715d5bba8e60f9107e78e218be 1 parent 62a9217
@chriso authored
Showing with 5 additions and 5 deletions.
  1. +3 −3 cli.js
  2. +1 −1  examples/command.js
  3. +1 −1  package.json
View
6 cli.js
@@ -260,7 +260,7 @@ cli.parse = function (opts, command_def) {
opt_list = opts || {};
commands = command_def;
command_list = commands || [];
- if (typeof commands === 'object') {
+ if (!Array.isArray(commands)) {
command_list = Object.keys(commands);
}
while (o = cli.next()) {
@@ -573,7 +573,7 @@ cli.getUsage = function () {
if (desc.length <= desc_len) {
return desc;
}
- var desc_words = desc.split(' '), chars = 0, word;
+ var desc_words = (desc+'').split(' '), chars = 0, word;
while (desc_words.length) {
truncated += (word = desc_words.shift()) + ' ';
chars += word.length;
@@ -662,7 +662,7 @@ cli.getUsage = function () {
}
if (command_list.length) {
console.error('\n\x1b[1mCommands\x1b[0m: ');
- if (typeof commands === 'object') {
+ if (!Array.isArray(commands)) {
for (var c in commands) {
line = ' ' + pad(c, switch_pad - 2);
line += trunc_desc(line, commands[c]);
View
2  examples/command.js
@@ -13,4 +13,4 @@ var cli = require('cli');
cli.parse(null, ['install', 'test', 'edit', 'remove', 'uninstall', 'ls']);
-console.log('Command is: ' + cli.command);
+console.log('Command is: ' + cli.command);
View
2  package.json
@@ -1,6 +1,6 @@
{ "name" : "cli",
"description" : "A tool for rapidly building command line apps",
- "version" : "0.3.2",
+ "version" : "0.3.3",
"homepage" : "http://github.com/chriso/cli",
"keywords" : ["cli","command line","opts","parseopt","opt","args","console","argsparse","optparse","daemon","autocomplete","command","autocompletion"],
"author" : "Chris O'Hara <cohara87@gmail.com>",
Please sign in to comment.
Something went wrong with that request. Please try again.