print help for sub-commands

This commit is contained in:
AJ ONeal 2017-11-09 17:32:03 -07:00
parent 83030fb416
commit e99b9ff4d6
1 changed files with 44 additions and 12 deletions

View File

@ -55,8 +55,12 @@ function parseArgs(argv, opts) {
function printCmds(cmds) {
console.info('');
console.info('\t' + defaults.main + ' ' + rpad(COMMAND, maxCmdLen), ' # description');
console.info('\t' + '------------------------------');
var title = defaults.main + ' ' + rpad(COMMAND, maxCmdLen) + ' # description';
var bars = title.replace(/./g, '-').split('');
bars[bars.length - ' # description'.length] = ' ';
bars[bars.length - (' # description'.length + 1)] = ' ';
console.info('\t' + title);
console.info('\t' + bars.join(''));
cmds.forEach(printCmd);
console.info('');
}
@ -94,20 +98,48 @@ function parseArgs(argv, opts) {
return;
}
console.info('');
console.info('Here are all the "' + command + '"-related commands:');
printCmds(
opts.commands.filter(function (desc) {
// matches the first part of the command
// and has second parts
if (arg1 === arg1.split(':')[0] && opts.commands.filter(function (desc) {
return arg1 === desc[0].split(/\s+/)[0].split(':')[0] && desc[0].split(/\s+/)[0].split(':');
}).length > 1) {
console.info('');
console.info("Here are all the '" + command + "'-related commands:");
printCmds(
opts.commands.filter(function (desc) {
var pair = desc[0].split(/\s+/)[0];
var psub = pair.split(sep)[0];
maxPairLen = Math.max(maxPairLen, pair.length);
if (arg1 === psub || arg1 === pair) {
maxCmdLen = Math.max(maxCmdLen, pair.length);
return true;
}
})
);
console.info('');
} else {
console.info('');
console.info("Here are all the options and flags for '" + arg1 + "':");
console.info('');
opts.commands.some(function (desc) {
var pair = desc[0].split(/\s+/)[0];
var psub = pair.split(sep)[0];
maxPairLen = Math.max(maxPairLen, pair.length);
if (arg1 === psub || arg1 === pair) {
maxCmdLen = Math.max(maxCmdLen, pair.length);
return true;
if (arg1 !== psub && arg1 !== pair) {
return false;
}
})
);
console.info('');
maxCmdLen = Math.max(maxCmdLen, pair.length);
console.log('\t' + desc[0] + '\t# ' + desc[1]);
(desc[2]||[]).forEach(function (flag) {
var pair = flag.split(', ');
var f = pair.shift();
var d = pair.join(', ');
console.log('\t\t' + f + ' # ' + d);
});
return true;
});
console.info('');
}
}
if (-1 === Object.keys(pairsMap).indexOf(cmd)) {