-
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathgeneral.js
More file actions
68 lines (58 loc) · 2.2 KB
/
general.js
File metadata and controls
68 lines (58 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';
const { writeText, style } = require('../../utils/serverless-utils/log');
const { version } = require('../../../package');
const globalOptions = require('../commands-schema/common-options/global');
const resolveInput = require('../resolve-input');
const generateCommandUsage = require('./generate-command-usage');
const renderOptions = require('./options');
module.exports = (loadedPlugins) => {
const { commandsSchema } = resolveInput();
writeText(
`Serverless Framework v${version}`,
null,
style.aside('Usage'),
'serverless <command> <options>',
'sls <command> <options>',
null,
style.aside('Options')
);
renderOptions(globalOptions, { shouldWriteModernOnly: true });
const allCommands = new Map(
Array.from(commandsSchema).filter(([commandName, { isHidden }]) => commandName && !isHidden)
);
const mainCommands = new Map(
Array.from(allCommands).filter(([, { groupName }]) => groupName === 'main')
);
if (mainCommands.size) {
writeText(null, style.aside('Main commands'));
for (const [commandName, commandSchema] of mainCommands) {
writeText(generateCommandUsage(commandName, commandSchema));
}
writeText(null, style.aside('Other commands'));
} else {
writeText(null, style.aside('All commands'));
}
const extensionCommandsSchema = new Map();
for (const [commandName, commandSchema] of allCommands) {
if (commandSchema.isExtension) {
if (!extensionCommandsSchema.has(commandSchema.sourcePlugin)) {
extensionCommandsSchema.set(commandSchema.sourcePlugin, new Map());
}
extensionCommandsSchema.get(commandSchema.sourcePlugin).set(commandName, commandSchema);
continue;
}
if (commandSchema.groupName === 'main') continue;
writeText(generateCommandUsage(commandName, commandSchema));
}
if (loadedPlugins.size) {
if (extensionCommandsSchema.size) {
for (const [plugin, pluginCommandsSchema] of extensionCommandsSchema) {
writeText(null, style.aside(plugin.constructor.name));
for (const [commandName, commandSchema] of pluginCommandsSchema) {
writeText(generateCommandUsage(commandName, commandSchema));
}
}
}
}
writeText();
};