Skip to content

Commit 3effb85

Browse files
committed
fix: various bugs
1 parent 6f082ad commit 3effb85

File tree

10 files changed

+34
-19
lines changed

10 files changed

+34
-19
lines changed

messages/list.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"description": "list auth connection information"
2+
"description": "list auth connection information",
3+
"noResultsFound": "No results found"
34
}

messages/messages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"instanceUrl": "the login URL of the instance the org lives on",
2626
"authorizeCommandSuccess": "Successfully authorized %s with org ID %s",
2727
"authorizeCommandCloseBrowser": "You may now close the browser",
28-
"warnAuth": "Logging in to a business or production org is not recommended on a demo or shared machine. Please run \"sfdx auth:logout --targetusername <your username> --noprompt\" when finished using this org, which is similar to logging out of the org in the browser.\n\nDo you want to authorize this org, %s, for use with the Salesforce CLI (y/n)?",
28+
"warnAuth": "Logging in to a business or production org is not recommended on a demo or shared machine. Please run \"sfdx auth:logout --targetusername <your username> --noprompt\" when finished using this org, which is similar to logging out of the org in the browser.\n\nDo you want to authorize this org for use with the Salesforce CLI (y/n)?",
2929
"noPromptAuth": "do not prompt for auth confirmation in demo mode",
3030
"disableMasking": "disable masking of user input (for use with problematic terminals)",
3131
"clientSecretStdin": "OAuth client secret of personal connected app?"

messages/sfdxurl.store.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "authorize an org using an SFDX auth URL\nThe file must have the format \"%s\" or \"%s\".\nThe file must contain only the URL or be a JSON file that has a top-level property named sfdxAuthUrl.\nUse this command to get the SFDX auth URL for a Dev Hub org you have already authorized:\n\n $ sfdx force:org:display -u <DevHub> --verbose",
2+
"description": "authorize an org using an SFDX auth URL\nAuthorize a Salesforce org using an SFDX auth URL stored within a file. The file must have the format \"%s\" or \"%s\".\nThe file must contain only the URL or be a JSON file that has a top-level property named sfdxAuthUrl.\nUse this command to get the SFDX auth URL for a Dev Hub org you have already authorized:\n\n $ sfdx force:org:display -u <DevHub> --verbose",
33
"file": "path to a file containing the sfdx url",
44
"examples": [
55
"sfdx auth:sfdxurl:store -f <path to sfdxAuthUrl file>",

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
"dependencies": {
88
"@oclif/config": "^1.17.0",
99
"@salesforce/command": "^3.0.3",
10-
"@salesforce/core": "^2.13.0",
10+
"@salesforce/core": "^2.14.0",
1111
"@salesforce/kit": "^1.3.3",
12+
"chalk": "^4.1.0",
1213
"open": "^7.3.0",
1314
"tslib": "^1"
1415
},

src/commands/auth/device/login.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default class Login extends SfdxCommand {
7373
if (approval) {
7474
const authInfo = await deviceOauthService.authorizeAndSave(approval);
7575
await Common.handleSideEffects(authInfo, this.flags);
76-
const fields = authInfo.getFields();
76+
const fields = authInfo.getFields(true);
7777
const successMsg = messages.getMessage('success', [fields.username]);
7878
this.ux.log(successMsg);
7979
return fields;

src/commands/auth/jwt/grant.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default class Grant extends SfdxCommand {
6666
try {
6767
const authInfo = await this.initAuthInfo();
6868
await Common.handleSideEffects(authInfo, this.flags);
69-
result = authInfo.getFields();
69+
result = authInfo.getFields(true);
7070
} catch (err) {
7171
throw SfdxError.create('@salesforce/plugin-auth', 'jwt.grant', 'JwtGrantError', [err.message]);
7272
}

src/commands/auth/list.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@ export default class List extends SfdxCommand {
2525
public static readonly description = messages.getMessage('description');
2626
public static readonly flagsConfig: FlagsConfig = {};
2727
public async run(): Promise<Authorization[]> {
28-
const auths = await AuthInfo.listAllAuthorizations();
29-
const hasErrors = auths.filter((auth) => !!auth.error).length > 0;
30-
const columns = ['alias', 'username', 'orgId', 'instanceUrl', 'oauthMethod'];
31-
if (hasErrors) {
32-
columns.push('error');
28+
try {
29+
const auths = await AuthInfo.listAllAuthorizations();
30+
const hasErrors = auths.filter((auth) => !!auth.error).length > 0;
31+
const columns = ['alias', 'username', 'orgId', 'instanceUrl', 'oauthMethod'];
32+
if (hasErrors) {
33+
columns.push('error');
34+
}
35+
this.ux.styledHeader('authenticated orgs');
36+
this.ux.table(auths, columns);
37+
return auths;
38+
} catch (err) {
39+
this.ux.log(messages.getMessage('noResultsFound'));
40+
return [];
3341
}
34-
this.ux.styledHeader('authenticated orgs');
35-
this.ux.table(auths, columns);
36-
return auths;
3742
}
3843
}

src/commands/auth/sfdxurl/store.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default class Store extends SfdxCommand {
5757

5858
await Common.handleSideEffects(authInfo, this.flags);
5959

60-
const result = authInfo.getFields();
60+
const result = authInfo.getFields(true);
6161
const successMsg = commonMessages.getMessage('authorizeCommandSuccess', [result.username, result.orgId]);
6262
this.ux.log(successMsg);
6363
return result;

src/commands/auth/web/login.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default class Login extends SfdxCommand {
7373
try {
7474
const authInfo = await this.executeLoginFlow(oauthConfig);
7575
await Common.handleSideEffects(authInfo, this.flags);
76-
const fields = authInfo.getFields();
76+
const fields = authInfo.getFields(true);
7777
const successMsg = commonMessages.getMessage('authorizeCommandSuccess', [fields.username, fields.orgId]);
7878
this.ux.log(successMsg);
7979
return fields;

src/prompts.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@
66
*/
77
import { Messages, Global, Mode } from '@salesforce/core';
88
import { UX } from '@salesforce/command';
9+
import * as chalk from 'chalk';
910

1011
Messages.importMessagesDirectory(__dirname);
1112
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'messages');
1213

14+
function dimMessage(message: string): string {
15+
return chalk.dim(message);
16+
}
17+
1318
export class Prompts {
1419
public static async shouldExitCommand(ux: UX, noPrompt?: boolean, message?: string): Promise<boolean> {
1520
if (noPrompt || Global.getEnvironmentMode() !== Mode.DEMO) {
1621
return false;
1722
} else {
18-
const answer = await ux.prompt(message || messages.getMessage('warnAuth'));
23+
const msg = dimMessage(message || messages.getMessage('warnAuth'));
24+
const answer = await ux.prompt(msg);
1925
return Prompts.answeredNo(answer);
2026
}
2127
}
@@ -24,13 +30,15 @@ export class Prompts {
2430
if (noPrompt || Global.getEnvironmentMode() === Mode.DEMO) {
2531
return true;
2632
} else {
27-
const answer = await ux.prompt(message || messages.getMessage('warnAuth'));
33+
const msg = dimMessage(message || messages.getMessage('warnAuth'));
34+
const answer = await ux.prompt(msg);
2835
return Prompts.answeredYes(answer);
2936
}
3037
}
3138

3239
public static async askForClientSecret(ux: UX, disableMasking: false): Promise<string> {
33-
return ux.prompt(messages.getMessage('clientSecretStdin'), {
40+
const msg = dimMessage(messages.getMessage('clientSecretStdin'));
41+
return ux.prompt(msg, {
3442
type: disableMasking ? 'normal' : 'hide',
3543
});
3644
}

0 commit comments

Comments
 (0)