get.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ConfigGetCommand = void 0;
  4. const tslib_1 = require("tslib");
  5. const string_1 = require("@ionic/cli-framework/utils/string");
  6. const utils_terminal_1 = require("@ionic/utils-terminal");
  7. const chalk_1 = tslib_1.__importDefault(require("chalk"));
  8. const lodash = tslib_1.__importStar(require("lodash"));
  9. const util = tslib_1.__importStar(require("util"));
  10. const constants_1 = require("../../constants");
  11. const color_1 = require("../../lib/color");
  12. const base_1 = require("./base");
  13. class ConfigGetCommand extends base_1.BaseConfigCommand {
  14. async getMetadata() {
  15. const projectFile = this.project ? (0, utils_terminal_1.prettyPath)(this.project.filePath) : constants_1.PROJECT_FILE;
  16. return {
  17. name: 'get',
  18. type: 'global',
  19. summary: 'Print config values',
  20. description: `
  21. This command reads and prints configuration values from the project's ${(0, color_1.strong)(projectFile)} file. It can also operate on the global CLI configuration (${(0, color_1.strong)('~/.ionic/config.json')}) using the ${(0, color_1.input)('--global')} option.
  22. For nested properties, separate nest levels with dots. For example, the property name ${(0, color_1.input)('integrations.cordova')} will look in the ${(0, color_1.strong)('integrations')} object for the ${(0, color_1.strong)('cordova')} property.
  23. Without a ${(0, color_1.input)('property')} argument, this command prints out the entire config.
  24. For multi-app projects, this command is scoped to the current project by default. To operate at the root of the project configuration file instead, use the ${(0, color_1.input)('--root')} option.
  25. If you are using this command programmatically, you can use the ${(0, color_1.input)('--json')} option.
  26. This command will sanitize config output for known sensitive fields (disabled when using ${(0, color_1.input)('--json')}).
  27. `,
  28. inputs: [
  29. {
  30. name: 'property',
  31. summary: 'The property name you wish to get',
  32. },
  33. ],
  34. options: [
  35. {
  36. name: 'global',
  37. summary: 'Use global CLI config',
  38. type: Boolean,
  39. aliases: ['g'],
  40. },
  41. {
  42. name: 'json',
  43. summary: 'Output config values in JSON',
  44. type: Boolean,
  45. groups: ["advanced" /* MetadataGroup.ADVANCED */],
  46. },
  47. {
  48. name: 'root',
  49. summary: `Operate on root of ${(0, color_1.strong)(projectFile)}`,
  50. type: Boolean,
  51. hint: (0, color_1.weak)('[multi-app]'),
  52. groups: ["advanced" /* MetadataGroup.ADVANCED */],
  53. },
  54. ],
  55. exampleCommands: ['', 'id', '--global user.email', '-g npmClient'],
  56. };
  57. }
  58. async run(inputs, options) {
  59. const ctx = this.generateContext(inputs, options);
  60. const conf = (0, base_1.getConfigValue)(ctx);
  61. this.printConfig(ctx, conf);
  62. }
  63. printConfig(ctx, v) {
  64. const { global, json } = ctx;
  65. if (json) {
  66. process.stdout.write(this.jsonStringify(v));
  67. }
  68. else {
  69. if (global && v && typeof v === 'object') {
  70. const columns = lodash.entries(v)
  71. .map(([key, value]) => [key, this.sanitizeEntry(key, value)])
  72. .map(([key, value]) => [(0, color_1.strong)(key), util.inspect(value, { colors: chalk_1.default.level > 0 })]);
  73. columns.sort((a, b) => (0, string_1.strcmp)(a[0], b[0]));
  74. this.env.log.rawmsg((0, utils_terminal_1.columnar)(columns, constants_1.COLUMNAR_OPTIONS));
  75. }
  76. else {
  77. this.env.log.rawmsg(util.inspect(v, { depth: Infinity, colors: chalk_1.default.level > 0 }));
  78. }
  79. }
  80. }
  81. sanitizeEntry(key, value) {
  82. if (key.includes('tokens')) {
  83. return '*****';
  84. }
  85. return value;
  86. }
  87. }
  88. exports.ConfigGetCommand = ConfigGetCommand;