Skip to content

Commit b51fff6

Browse files
committed
Merge pull request #34 from mizunashi-mana/fix-help-output
Fix help output
2 parents 3ff6af8 + 53f22b6 commit b51fff6

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lib/commands.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
var _ = require('lodash');
22

3+
// Helper function for print help
4+
// indented output by spaces
5+
function indent_output(n, name, description) {
6+
if (!n) {
7+
n = 0;
8+
}
9+
10+
console.log(
11+
_.repeat(' ', n)
12+
+ name
13+
+ _.repeat(' ', 32 - n * 4 - name.length)
14+
+ description
15+
);
16+
}
17+
318
// Print help for a list of commands
419
// It prints the command and its description, then all the options
520
function help(commands) {
621
_.each(commands, function(command) {
7-
console.log(' '+command.name, '\t', command.description);
22+
indent_output(1, command.name, command.description);
823
_.each(command.options || [], function(option) {
924
var after = [];
1025

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

17-
console.log(' --'+option.name, '\t', option.description, after);
32+
var optname = '--';
33+
if (typeof option.defaults === 'boolean') optname += '[no-]';
34+
optname += option.name;
35+
indent_output(2, optname, option.description + ' ' + after);
1836
});
1937
console.log('');
2038
});

0 commit comments

Comments
 (0)