-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelete.ts
78 lines (54 loc) · 2.16 KB
/
delete.ts
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
72
73
74
75
76
77
78
import { flags } from '@oclif/command';
import Base from '../../../base';
import { cli } from 'cli-ux';
const pjson = require('../../../../package.json');
export default class DataPlanVersionDelete extends Base {
static description = `Deletes a Data Plan Version and uploads to mParticle
Data Plans are comprised of one or more Data Plan Versions.
A Version Document can be fetched by using your account credentials and a --versionNumber and --dataPlanId.
Note: Delete will NOT read dataPlanId or versionNumber from config as a precaution to prevent accidental deletion of records
For more information, visit: ${pjson.homepage}
`;
static aliases = ['plan:dpv:delete'];
static examples = [
`$ mp planning:data-plan-versions:delete --workspaceId=[WORKSPACE_ID] --dataPlanId=[DATA_PLAN_ID] --versionNumber=[VERSION_NUMBER]`,
];
static flags = {
...Base.flags,
dataPlanId: flags.string({
description: 'Data Plan ID',
}),
versionNumber: flags.integer({
description: 'Data Plan Version Number',
}),
};
async run() {
const { flags } = this.parse(DataPlanVersionDelete);
// Should not read from config to prevent accidental delete
const versionNumber = flags.versionNumber;
const dataPlanId = flags.dataPlanId;
if (!dataPlanId || !versionNumber) {
this.error('Missing Data Plan ID and Version Number');
}
const confirmDelete = await cli.confirm('Please confirm deletion [y/n]');
if (!confirmDelete) {
cli.action.stop;
this.exit(0);
}
const dataPlanService = this.getDataPlanService(this.credentials);
const message = 'Deleting Data Plan Version';
cli.action.start(message);
try {
await dataPlanService.deleteDataPlanVersion(dataPlanId, versionNumber);
this.log(`Deleted Data Plan Version: '${dataPlanId}:v${versionNumber}'`);
} catch (error) {
this._debugLog('Data Plan Version Delete Error', error);
if (error.errors) {
const errorMessage = 'Data Plan Version Delete Failed:';
this.error(this._generateErrorList(errorMessage, error.errors));
}
this.error(error);
}
cli.action.stop();
}
}