/
delete.ts
74 lines (50 loc) · 1.83 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
import { flags } from '@oclif/command';
import Base from '../../../base';
import { cli } from 'cli-ux';
const pjson = require('../../../../package.json');
export default class DataPlanDelete extends Base {
static description = `Deletes a Data Plan and uploads to mParticle
Data Plans are comprised of one or more Data Plan Versions.
A Data Plan can be fetched using your account credentials and using a valid --dataPlanId
Note: Delete will NOT read dataPlanId from config as a precaution to prevent accidental deletion of records
For more information, visit: ${pjson.homepage}
`;
static aliases = ['plan:dp:delete'];
static examples = [
`$ mp planning:data-plan:delete --workspaceId=[WORKSPACE_ID] --dataPlanId=[DATA_PLAN_ID]`,
];
static flags = {
...Base.flags,
dataPlanId: flags.string({
description: 'Data Plan ID',
}),
};
async run() {
const { flags } = this.parse(DataPlanDelete);
// Should not read from config to prevent accidental delete
const dataPlanId = flags.dataPlanId;
if (!dataPlanId) {
this.error('Missing Data Plan ID');
}
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';
cli.action.start(message);
try {
await dataPlanService.deleteDataPlan(dataPlanId);
this.log(`Deleted Data Plan with ID '${dataPlanId}'`);
} catch (error) {
this._debugLog('Data Plan Delete Error', error);
if (error.errors) {
const errorMessage = 'Data Plan Delete Failed:';
this.error(this._generateErrorList(errorMessage, error.errors));
}
this.error(error);
}
cli.action.stop();
}
}