diff --git a/lib/commands.js b/lib/commands.js index de8e5a6..f1523e2 100644 --- a/lib/commands.js +++ b/lib/commands.js @@ -1,10 +1,25 @@ var _ = require('lodash'); +// Helper function for print help +// indented output by spaces +function indent_output(n, name, description) { + if (!n) { + n = 0; + } + + console.log( + _.repeat(' ', n) + + name + + _.repeat(' ', 32 - n * 4 - name.length) + + description + ); +} + // Print help for a list of commands // It prints the command and its description, then all the options function help(commands) { _.each(commands, function(command) { - console.log(' '+command.name, '\t', command.description); + indent_output(1, command.name, command.description); _.each(command.options || [], function(option) { var after = []; @@ -14,7 +29,10 @@ function help(commands) { if (after.length > 0) after = "("+after.join("; ")+")"; else after = ""; - console.log(' --'+option.name, '\t', option.description, after); + var optname = '--'; + if (typeof option.defaults === 'boolean') optname += '[no-]'; + optname += option.name; + indent_output(2, optname, option.description + ' ' + after); }); console.log(''); });