-
Notifications
You must be signed in to change notification settings - Fork 682
Expand file tree
/
Copy pathunset.ts
More file actions
71 lines (61 loc) · 2.71 KB
/
unset.ts
File metadata and controls
71 lines (61 loc) · 2.71 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
69
70
71
import { MetadataGroup, validators } from '@ionic/cli-framework';
import { prettyPath } from '@ionic/utils-terminal';
import * as path from 'path';
import { PROJECT_FILE } from '../../constants';
import { CommandLineInputs, CommandLineOptions, CommandMetadata } from '../../definitions';
import { input, strong, weak } from '../../lib/color';
import { DEFAULT_CONFIG_DIRECTORY } from '../../lib/config';
import { FatalException } from '../../lib/errors';
import { BaseConfigCommand, getConfigValue, unsetConfigValue } from './base';
export class ConfigUnsetCommand extends BaseConfigCommand {
async getMetadata(): Promise<CommandMetadata> {
const projectFile = this.project ? prettyPath(this.project.filePath) : PROJECT_FILE;
return {
name: 'unset',
type: 'global',
summary: 'Delete config values',
description: `
This command deletes configuration values from the project's ${strong(prettyPath(projectFile))} file. It can also operate on the global CLI configuration (${strong(path.join(DEFAULT_CONFIG_DIRECTORY, 'config.json'))}) using the ${input('--global')} option.
For nested properties, separate nest levels with dots. For example, the property name ${input('integrations.cordova')} will look in the ${strong('integrations')} object for the ${strong('cordova')} property.
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 ${input('--root')} option.
`,
inputs: [
{
name: 'property',
summary: 'The property name you wish to delete',
validators: [validators.required],
},
],
options: [
{
name: 'global',
summary: 'Use global CLI config',
type: Boolean,
aliases: ['g'],
},
{
name: 'root',
summary: `Operate on root of ${strong(prettyPath(projectFile))}`,
type: Boolean,
hint: weak('[multi-app]'),
groups: [MetadataGroup.ADVANCED],
},
],
exampleCommands: ['', 'type', '--global git.setup', '-g interactive'],
};
}
async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void> {
const ctx = this.generateContext(inputs, options);
const { property } = ctx;
if (typeof property === 'undefined') {
throw new FatalException(`Cannot unset config entry without a property.`);
}
const propertyExists = typeof getConfigValue(ctx) !== 'undefined';
unsetConfigValue({ ...ctx, property });
if (propertyExists) {
this.env.log.ok(`${input(property)} unset!`);
} else {
this.env.log.warn(`Property ${input(property)} does not exist--cannot unset.`);
}
}
}