1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const guards_1 = require("../guards");
|
4 | const color_1 = require("../lib/color");
|
5 | const command_1 = require("../lib/command");
|
6 | class HelpCommand extends command_1.Command {
|
7 | async getMetadata() {
|
8 | return {
|
9 | name: 'help',
|
10 | type: 'global',
|
11 | summary: 'Provides help for a certain command',
|
12 | exampleCommands: ['start'],
|
13 | inputs: [
|
14 | {
|
15 | name: 'command',
|
16 | summary: 'The command you desire help with',
|
17 | },
|
18 | ],
|
19 | options: [
|
20 | {
|
21 | name: 'json',
|
22 | summary: 'Print help in JSON format',
|
23 | type: Boolean,
|
24 | },
|
25 | ],
|
26 | groups: ["hidden" ],
|
27 | };
|
28 | }
|
29 | async run(inputs, options) {
|
30 | const { CommandSchemaHelpFormatter, CommandStringHelpFormatter, NamespaceSchemaHelpFormatter, NamespaceStringHelpFormatter } = await Promise.resolve().then(() => require('../lib/help'));
|
31 | const location = await this.namespace.locate(inputs);
|
32 | if (guards_1.isCommand(location.obj)) {
|
33 | const formatterOptions = { location, command: location.obj };
|
34 | const formatter = options['json'] ? new CommandSchemaHelpFormatter(formatterOptions) : new CommandStringHelpFormatter(formatterOptions);
|
35 | this.env.log.rawmsg(await formatter.format());
|
36 | }
|
37 | else {
|
38 | if (location.args.length > 0) {
|
39 | this.env.log.error(`Unable to find command: ${color_1.input(inputs.join(' '))}` +
|
40 | (this.project ? '' : '\nYou may need to be in an Ionic project directory.'));
|
41 | }
|
42 | const now = new Date();
|
43 | const version = this.env.ctx.version;
|
44 | const suffix = now.getMonth() === 9 && now.getDate() === 31 ? ' 🎃' : '';
|
45 | const formatterOptions = {
|
46 | inProject: this.project ? true : false,
|
47 | version: version + suffix,
|
48 | location,
|
49 | namespace: location.obj,
|
50 | };
|
51 | const formatter = options['json'] ? new NamespaceSchemaHelpFormatter(formatterOptions) : new NamespaceStringHelpFormatter(formatterOptions);
|
52 | this.env.log.rawmsg(await formatter.format());
|
53 | }
|
54 | }
|
55 | }
|
56 | exports.HelpCommand = HelpCommand;
|