generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdisplay.ts
60 lines (52 loc) · 1.66 KB
/
display.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
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as os from 'os';
import { SfdxCommand } from '@salesforce/command';
import { Messages, SfdxError } from '@salesforce/core';
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-limits', 'display');
type ApiLimit = {
name: string;
max: number;
remaining: number;
};
interface Result {
[key: string]: {
Max: number;
Remaining: number;
};
}
export class LimitsApiDisplayCommand extends SfdxCommand {
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessage('examples').split(os.EOL);
public static readonly requiresUsername = true;
public async run(): Promise<ApiLimit[]> {
try {
const conn = this.org.getConnection();
const geturl = `${conn.instanceUrl}/services/data/v${conn.version}/limits`;
const result = (await conn.request(geturl)) as Result;
const limits: ApiLimit[] = [];
Object.keys(result).map((limitName) => {
limits.push({
name: limitName,
max: result[limitName].Max,
remaining: result[limitName].Remaining,
});
});
this.ux.table(limits, {
columns: [
{ key: 'name', label: 'Name' },
{ key: 'remaining', label: 'Remaining' },
{ key: 'max', label: 'Max' },
],
});
return limits;
} catch (err) {
throw SfdxError.wrap(err);
}
}
}