-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathdebug.ts
46 lines (37 loc) · 1.61 KB
/
debug.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
import { flags, SfdxCommand } from '@salesforce/command';
import userIdLookup = require('../../../../shared/userIdLookup');
import { QueryResult } from './../../../../shared/typeDefs';
export default class UserLightningDebug extends SfdxCommand {
public static description = 'set the user to debug mode';
public static examples = [
`sfdx shane:user:lightning:debug
// puts the default user in lightning debug mode
`,
`sfdx shane:user:lightning:debug -g Sarah -l McLaughlin
// puts the named user in lightning debug mode
`
];
protected static flagsConfig = {
firstname: flags.string({char: 'g', description: 'first (given) name of the user--keeping -f for file for consistency' }),
lastname: flags.string({char: 'l', description: 'last name of the user' })
};
protected static requiresUsername = true;
public async run(): Promise<any> { // tslint:disable-line:no-any
// this.org is guaranteed because requiresUsername=true, as opposed to supportsUsername
const conn = this.org.getConnection();
let userId;
if (this.flags.lastname && this.flags.firstname) {
const user = await userIdLookup.getUserId(conn, this.flags.lastname, this.flags.firstname);
userId = user.Id;
} else {
const users = <QueryResult> await conn.query(`select id from user where username = '${this.org.getUsername()}'`);
userId = users.records[0].Id;
}
const updateResult = await conn.sobject('User').update({
Id: userId,
UserPreferencesUserDebugModePref: true
});
this.ux.log(`added lightning debug mode on user ${userId}`);
return updateResult;
}
}