help.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.HelpCommand = void 0;
  27. const guards_1 = require("../guards");
  28. const color_1 = require("../lib/color");
  29. const command_1 = require("../lib/command");
  30. class HelpCommand extends command_1.Command {
  31. async getMetadata() {
  32. return {
  33. name: 'help',
  34. type: 'global',
  35. summary: 'Provides help for a certain command',
  36. exampleCommands: ['start'],
  37. inputs: [
  38. {
  39. name: 'command',
  40. summary: 'The command you desire help with',
  41. },
  42. ],
  43. options: [
  44. {
  45. name: 'json',
  46. summary: 'Print help in JSON format',
  47. type: Boolean,
  48. },
  49. ],
  50. groups: ["hidden" /* MetadataGroup.HIDDEN */],
  51. };
  52. }
  53. async run(inputs, options) {
  54. const { CommandSchemaHelpFormatter, CommandStringHelpFormatter, NamespaceSchemaHelpFormatter, NamespaceStringHelpFormatter } = await Promise.resolve().then(() => __importStar(require('../lib/help')));
  55. const location = await this.namespace.locate(inputs);
  56. if ((0, guards_1.isCommand)(location.obj)) {
  57. const formatterOptions = { location, command: location.obj };
  58. const formatter = options['json'] ? new CommandSchemaHelpFormatter(formatterOptions) : new CommandStringHelpFormatter(formatterOptions);
  59. this.env.log.rawmsg(await formatter.format());
  60. }
  61. else {
  62. if (location.args.length > 0) {
  63. this.env.log.error(`Unable to find command: ${(0, color_1.input)(inputs.join(' '))}` +
  64. (this.project ? '' : '\nYou may need to be in an Ionic project directory.'));
  65. }
  66. const now = new Date();
  67. const version = this.env.ctx.version;
  68. const suffix = now.getMonth() === 9 && now.getDate() === 31 ? ' 🎃' : '';
  69. const formatterOptions = {
  70. inProject: this.project ? true : false,
  71. version: version + suffix,
  72. location,
  73. namespace: location.obj,
  74. };
  75. const formatter = options['json'] ? new NamespaceSchemaHelpFormatter(formatterOptions) : new NamespaceStringHelpFormatter(formatterOptions);
  76. this.env.log.rawmsg(await formatter.format());
  77. }
  78. }
  79. }
  80. exports.HelpCommand = HelpCommand;