Skip to content

Commit b20ac79

Browse files
committed
feat: do not display url for basic org:open
1 parent 2f92e1d commit b20ac79

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

messages/open.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"urlonly": "display navigation URL, but don’t launch browser",
1313
"containerAction": "You are in a headless environment. To access the org %s, open this URL in a browser:\n\n%s",
1414
"humanSuccess": "Access org %s as user %s with the following URL: %s",
15+
"humanSuccessNoUrl": "Opening org %s as user %s",
1516
"domainWaiting": "Waiting to resolve the Lightning Experience-enabled custom domain...",
1617
"domainTimeoutError": "The Lightning Experience-enabled custom domain is unavailable.",
1718
"domainTimeoutAction": "The Lightning Experience-enabled custom domain may take a few more minutes to resolve. Try the \"force:org:open\" command again."

src/commands/force/org/open.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,28 @@ export class OrgOpenCommand extends SfdxCommand {
4545
const orgId = this.org.getOrgId();
4646
const username = this.org.getUsername();
4747
const output = { orgId, url, username };
48+
const containerMode = new Env().getBoolean('SFDX_CONTAINER_MODE');
4849

49-
this.ux.warn(sharedMessages.getMessage('SecurityWarning'));
50-
this.ux.log('');
50+
// security warning only for --json OR --urlonly OR containerMode
51+
if (this.flags.urlonly || this.flags.json || containerMode) {
52+
this.ux.warn(sharedMessages.getMessage('SecurityWarning'));
53+
this.ux.log('');
54+
}
5155

52-
if (new Env().getBoolean('SFDX_CONTAINER_MODE')) {
56+
if (containerMode) {
5357
// instruct the user that they need to paste the URL into the browser
5458
this.ux.styledHeader('Action Required!');
5559
this.ux.log(messages.getMessage('containerAction', [orgId, url]));
5660
return output;
5761
}
5862

59-
this.ux.log(messages.getMessage('humanSuccess', [orgId, username, url]));
60-
6163
if (this.flags.urlonly) {
64+
// this includes the URL
65+
this.ux.log(messages.getMessage('humanSuccess', [orgId, username, url]));
6266
return output;
6367
}
68+
69+
this.ux.log(messages.getMessage('humanSuccessNoUrl', [orgId, username]));
6470
// we actually need to open the org
6571
try {
6672
this.ux.startSpinner(messages.getMessage('domainWaiting'));
@@ -79,9 +85,8 @@ export class OrgOpenCommand extends SfdxCommand {
7985
throw SfdxError.wrap(err);
8086
}
8187

82-
const openOptions = this.flags.browser
83-
? { app: { name: open.apps[this.flags.browser as string] as open.AppName } }
84-
: {};
88+
const openOptions =
89+
typeof this.flags.browser === 'string' ? { app: { name: open.apps[this.flags.browser] as open.AppName } } : {};
8590

8691
await openUrl(url, openOptions);
8792
return output;

test/commands/force/org/open.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as utils from '../../../../src/shared/utils';
1111

1212
Messages.importMessagesDirectory(__dirname);
1313
const messages = Messages.loadMessages('@salesforce/plugin-org', 'open');
14+
const sharedMessages = Messages.loadMessages('@salesforce/plugin-org', 'messages');
1415

1516
const orgId = '000000000000000';
1617
const username = '[email protected]';
@@ -54,6 +55,7 @@ describe('open commands', () => {
5455
expect(response.status).to.equal(0);
5556
expect(testJsonStructure(response.result)).to.be.true;
5657
expect(response.result.url).to.equal(expectedDefaultUrl);
58+
expect(response.warnings).to.include(sharedMessages.getMessage('SecurityWarning'));
5759
});
5860

5961
test
@@ -64,6 +66,7 @@ describe('open commands', () => {
6466
expect(response.status).to.equal(0);
6567
expect(testJsonStructure(response.result)).to.be.true;
6668
expect(response.result.url).to.equal(expectedUrl);
69+
expect(response.warnings).to.include(sharedMessages.getMessage('SecurityWarning'));
6770
});
6871

6972
test
@@ -141,7 +144,7 @@ describe('open commands', () => {
141144
expect(response.status).to.equal(0);
142145
expect(testJsonStructure(response.result)).to.be.true;
143146
expect(response.result.url).to.equal(expectedUrl);
144-
147+
expect(response.warnings).to.include(sharedMessages.getMessage('SecurityWarning'));
145148
expect(spies.get('resolver').callCount).to.equal(0);
146149
});
147150

@@ -169,12 +172,22 @@ describe('open commands', () => {
169172
})
170173
.stdout()
171174
.command(['force:org:open', '--targetusername', username, '--path', testPath])
172-
.it('calls open and outputs proper success message', (ctx) => {
173-
expect(ctx.stdout).to.include(messages.getMessage('humanSuccess', [orgId, username, expectedUrl]));
175+
.it('calls open and outputs proper success message (no url)', (ctx) => {
176+
expect(ctx.stdout).to.include(messages.getMessage('humanSuccessNoUrl', [orgId, username]));
174177
expect(spies.get('resolver').callCount).to.equal(1);
175178
expect(spies.get('open').callCount).to.equal(1);
176179
});
177180

181+
test
182+
.do(() => {
183+
spies.set('resolver', stubMethod($$.SANDBOX, MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'));
184+
})
185+
.stdout()
186+
.command(['force:org:open', '--targetusername', username, '--path', testPath, '--urlonly'])
187+
.it('outputs proper warning and message (includes url for --urlonly)', (ctx) => {
188+
expect(ctx.stdout).to.include(messages.getMessage('humanSuccess', [orgId, username, expectedUrl]));
189+
});
190+
178191
test
179192
.do(() => {
180193
spies.set(

0 commit comments

Comments
 (0)