unset.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ConfigUnsetCommand = void 0;
  4. const cli_framework_1 = require("@ionic/cli-framework");
  5. const utils_terminal_1 = require("@ionic/utils-terminal");
  6. const constants_1 = require("../../constants");
  7. const color_1 = require("../../lib/color");
  8. const errors_1 = require("../../lib/errors");
  9. const base_1 = require("./base");
  10. class ConfigUnsetCommand extends base_1.BaseConfigCommand {
  11. async getMetadata() {
  12. const projectFile = this.project ? (0, utils_terminal_1.prettyPath)(this.project.filePath) : constants_1.PROJECT_FILE;
  13. return {
  14. name: 'unset',
  15. type: 'global',
  16. summary: 'Delete config values',
  17. description: `
  18. This command deletes configuration values from the project's ${(0, color_1.strong)((0, utils_terminal_1.prettyPath)(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.
  19. 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.
  20. 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.
  21. `,
  22. inputs: [
  23. {
  24. name: 'property',
  25. summary: 'The property name you wish to delete',
  26. validators: [cli_framework_1.validators.required],
  27. },
  28. ],
  29. options: [
  30. {
  31. name: 'global',
  32. summary: 'Use global CLI config',
  33. type: Boolean,
  34. aliases: ['g'],
  35. },
  36. {
  37. name: 'root',
  38. summary: `Operate on root of ${(0, color_1.strong)((0, utils_terminal_1.prettyPath)(projectFile))}`,
  39. type: Boolean,
  40. hint: (0, color_1.weak)('[multi-app]'),
  41. groups: ["advanced" /* MetadataGroup.ADVANCED */],
  42. },
  43. ],
  44. exampleCommands: ['', 'type', '--global git.setup', '-g interactive'],
  45. };
  46. }
  47. async run(inputs, options) {
  48. const ctx = this.generateContext(inputs, options);
  49. const { property } = ctx;
  50. if (typeof property === 'undefined') {
  51. throw new errors_1.FatalException(`Cannot unset config entry without a property.`);
  52. }
  53. const propertyExists = typeof (0, base_1.getConfigValue)(ctx) !== 'undefined';
  54. (0, base_1.unsetConfigValue)({ ...ctx, property });
  55. if (propertyExists) {
  56. this.env.log.ok(`${(0, color_1.input)(property)} unset!`);
  57. }
  58. else {
  59. this.env.log.warn(`Property ${(0, color_1.input)(property)} does not exist--cannot unset.`);
  60. }
  61. }
  62. }
  63. exports.ConfigUnsetCommand = ConfigUnsetCommand;