UNPKG

1.32 kBJavaScriptView Raw
1const commandLineUsage = require('command-line-usage');
2const map = require('lodash/map');
3const kebabCase = require('lodash/kebabCase');
4const behaviorHelpSections = require('./behaviorHelpSections');
5const getCommandOptions = require('../command/getCommandOptions');
6
7const displayCommandHelp = (app, commandName, command, input) => {
8
9 const desc = 'Description not provided.';
10
11 const sections = [];
12
13 sections.push({
14 header: `${app.commandName} ${commandName} (${app.appName} ${app.version})`,
15 content: command.description || desc
16 });
17
18 if (command.usage) {
19 sections.push({
20 header: 'Usage',
21 content: command.usage
22 });
23 }
24
25 if (getCommandOptions(app, command, input).length) {
26 sections.push({
27 header: 'Command options',
28 optionList: map(getCommandOptions(app, command, input), (option) => {
29 return { ...option, name: kebabCase(option.name) };
30 })
31 });
32 }
33
34 if (app.options && app.options.length) {
35 sections.push({
36 header: 'Global options',
37 optionList: map(app.options, (option) => {
38 return { ...option, name: kebabCase(option.name) };
39 })
40 });
41 }
42
43 const behaviors = behaviorHelpSections(app);
44
45 console.log(commandLineUsage([
46 ...sections,
47 ...behaviors
48 ]));
49};
50
51module.exports = displayCommandHelp;