Skip to content

Commit

Permalink
fix help output style
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizunashi Mana committed May 20, 2016
1 parent 3ff6af8 commit ab968d5
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions 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 = [];

Expand All @@ -14,7 +29,7 @@ function help(commands) {
if (after.length > 0) after = "("+after.join("; ")+")";
else after = "";

console.log(' --'+option.name, '\t', option.description, after);
indent_output(2, '--' + option.name, option.description + ' ' + after);
});
console.log('');
});
Expand Down

0 comments on commit ab968d5

Please sign in to comment.