Skip to content

Commit

Permalink
feat: disconnect orgs from env commands (#513)
Browse files Browse the repository at this point in the history
* feat: disconnect orgs from env commands

@W-12537051@

* chore: add warnings to direct folks to org commands

* fix: remove mention of orgs (#520)

---------

Co-authored-by: Juliet Shackell <[email protected]>
Co-authored-by: Shane McLaughlin <[email protected]>
  • Loading branch information
3 people authored Feb 21, 2023
1 parent 4b0735f commit 285c583
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 748 deletions.
18 changes: 4 additions & 14 deletions messages/display.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,11 @@ Display details about an environment.

Specify an environment with either the username you used when you logged into the environment with "sf login", or the alias you gave the environment when you created it. Run "sf env list" to view all your environments and their aliases.

Output depends on the type of environment. For example, scratch org details include the access token, alias, username of the associated Dev Hub, the creation and expiration date, the generated scratch org username, and more. Compute environment details include the alias, connected orgs, creation date, project name, and more.
Output depends on the type of environment.

# examples

- Display details about a scratch org with alias my-scratch-org:

<%= config.bin %> <%= command.id %> --target-env=my-scratch-org

- Specify a username instead of an alias:

<%= config.bin %> <%= command.id %> --target-env=[email protected]

- Specify JSON format and redirect output into a file:

<%= config.bin %> <%= command.id %> --target-env=my-scratch-org --json > tmp/MyOrdDesc.json
- <%- config.bin %> <%- command.id %> --target-env myEnv

# flags.target-env.summary

Expand All @@ -34,6 +24,6 @@ No results found.

No environment found for %s.

# error.NoDefaultEnv
# warning.orgsNoLongerSupported

No default environment found. Use -e or --target-env to specify an environment to display.
This command only displays functions environments. Use "%s org display" to display an org.
22 changes: 6 additions & 16 deletions messages/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ List the environments you’ve created or logged into.

# description

By default, the command displays active environments. For orgs, active means unexpired scratch orgs and orgs you’re currently logged into.
By default, the command displays active environments.

Output is displayed in multiple tables, one for each environment type. For example, the Salesforce Orgs table lists the non-scratch orgs you’re logged into, such as sandboxes, Dev Hubs, production orgs, and so on. Scratch orgs and compute environments get their own tables.

The two org tables show similar information, such as aliases, information about the org, and how you authorized (logged into) it, such as with a web browser or JWT. The scratch org table also shows the expiration date. For non-scratch orgs, the Username column refers to the user you logged into the org with. For scratch orgs it refers to the username that was generated for you when you created the scratch org. Your default scratch org or Dev Hub org is indicated with the "target-org" or "target-dev-hub" configuration variable, respectively, in the Config column.
Output is displayed in multiple tables, one for each environment type.

The compute environment table shows the alias, information about the connected orgs, the project name, and more.

Expand All @@ -26,14 +24,6 @@ Run "sf env display" to view details about a specific environment.

<%= config.bin %> <%= command.id %> --all

- Filter the output to list only orgs you authorized using a web browser; "Auth Method" is the name of a column:

<%= config.bin %> <%= command.id %> --filter "Auth Method=web"

- Display only the Aliases column and sort the aliases in descending order:

<%= config.bin %> <%= command.id %> --sort "-Aliases" --columns "Aliases"

- Don't truncate the displayed output and instead wrap text that's wider than your terminal:

<%= config.bin %> <%= command.id %> --no-truncate
Expand Down Expand Up @@ -74,14 +64,14 @@ Format in which to display the output.

Column to sort by (prepend '-' for descending).

# error.NoAuthsAvailable

No authenticated environments found. Log in or create an environment, and then try again.

# error.NoResultsFound

No results found.

# warning.RequestedColumnsNotPresentInEnvironment

The columns you specified (%s) aren't available in the table for environment "%s".

# warning.orgsNoLongerSupported

This command only lists functions environments. Use "%s org list" to list orgs.
22 changes: 9 additions & 13 deletions messages/open.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@ Open an environment in a web browser.

# description

You can open the following types of environments in a web browser: scratch orgs, sandboxes, Dev Hubs, and production orgs. Run "sf env list" to view your environments and their aliases and login usernames.

Each of your environments is associated with an instance URL, such as https://login.salesforce.com. To open a specific web page, specify the portion of the URL after "<URL>/" with the --path flag, such as /apex/YourPage to open a Visualforce page.
Each of your environments is associated with an instance URL, such as https://login.salesforce.com. To open a specific web page, specify the portion of the URL after "<URL>/" with the --path flag.

# examples

- Open the Visualforce page /apex/StartHere in a scratch org with alias test-org:
- Open the compute environment with alias "test-compute":

<%= config.bin %> <%= command.id %> --target-env test-org --path /apex/StartHere
<%= config.bin %> <%= command.id %> --target-env test-compute

- View the URL but don't launch it in a browser:

<%= config.bin %> <%= command.id %> --target-env test-org --path /apex/StartHere --url-only
<%= config.bin %> <%= command.id %> --target-env test-compute --url-only

- Open the environment in the Google Chrome browser:

<%= config.bin %> <%= command.id %> --target-env test-org --path /apex/StartHere --browser chrome
<%= config.bin %> <%= command.id %> --target-env test-compute --url-only --browser chrome

# flags.path.summary

Expand All @@ -34,12 +32,6 @@ Display the URL, but don’t launch it in a browser.

Login user or alias of the environment to open.

# flags.target-env.description

Specify the login user or alias that’s associated with the environment. For scratch orgs, the login user is generated by the command that created the scratch org. You can also set an alias for the scratch org when you create it.

For Dev Hubs, sandboxes, and production orgs, specify the alias you set when you logged into the org with "sf login".

# flags.browser.summary

Browser in which to open the environment.
Expand All @@ -63,3 +55,7 @@ The environment %s doesn't support being opened.
# error.ApplicationNotFound

Can't find application named %s.

# warning.orgsNoLongerSupported

This command only opens a function's environment. Use "%s org open" to open an org.
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@
"commands": "./lib/commands",
"bin": "sf",
"topicSeparator": " ",
"hooks": {
"sf:env:display": "./lib/hooks/envDisplay",
"sf:env:list": "./lib/hooks/envList"
},
"devPlugins": [
"@oclif/plugin-help",
"@oclif/plugin-command-snapshot",
Expand Down Expand Up @@ -114,4 +110,4 @@
"access": "public"
},
"main": "lib/index.js"
}
}
88 changes: 0 additions & 88 deletions schemas/hooks/sf-env-display.json

This file was deleted.

47 changes: 0 additions & 47 deletions schemas/hooks/sf-env-list.json

This file was deleted.

10 changes: 3 additions & 7 deletions src/commands/env/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,16 @@ export default class EnvDisplay extends SfCommand<JsonObject> {
};

public async run(): Promise<JsonObject> {
this.warn(messages.getMessage('warning.orgsNoLongerSupported', [this.config.bin]));
const { flags } = await this.parse(EnvDisplay);
// TODO: access this from ConfigAggregator once target-env config var is supported.
const targetEnv = flags['target-env'];

if (!targetEnv) throw messages.createError('error.NoDefaultEnv');

let data: JsonObject = {};

try {
const results = await SfHook.run(this.config, 'sf:env:display', { targetEnv });
const results = await SfHook.run(this.config, 'sf:env:display', { targetEnv: flags['target-env'] });
const result = results.successes.find((s) => !!s.result?.data)?.result || null;

if (!result) {
throw messages.createError('error.NoEnvFound', [targetEnv]);
throw messages.createError('error.NoEnvFound', [flags['target-env']]);
}

data = result.data;
Expand Down
8 changes: 1 addition & 7 deletions src/commands/env/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ const messages = Messages.loadMessages('@salesforce/plugin-env', 'list');

const envTypeValues = Object.keys(Env.EnvType);
const envOrderBy = (a: Env.Table<JsonObject>, b: Env.Table<JsonObject>): number => {
// both a && b are well known
if (envTypeValues.includes(a.type) && envTypeValues.includes(a.type)) {
if (a.type === Env.EnvType.salesforceOrgs && b.type !== Env.EnvType.salesforceOrgs) return -1;
if (a.type !== Env.EnvType.salesforceOrgs && b.type === Env.EnvType.salesforceOrgs) return 1;
if (a.type === Env.EnvType.scratchOrgs && b.type !== Env.EnvType.scratchOrgs) return -1;
return 1;
}
// both a && b are user defined - use natural sort
if (!envTypeValues.includes(a.type) && !envTypeValues.includes(a.type)) {
return a.type.localeCompare(b.type);
Expand Down Expand Up @@ -82,6 +75,7 @@ export default class EnvList extends SfCommand<Environments> {
private flags!: Interfaces.InferredFlags<typeof EnvList.flags>;

public async run(): Promise<Environments> {
this.warn(messages.getMessage('warning.orgsNoLongerSupported', [this.config.bin]));
this.flags = (await this.parse(EnvList)).flags;
const tableOpts = {
columns: this.flags.columns?.join(','),
Expand Down
3 changes: 2 additions & 1 deletion src/commands/env/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default class EnvOpen extends SfCommand<OpenResult> {
'target-env': Flags.string({
char: 'e',
summary: messages.getMessage('flags.target-env.summary'),
description: messages.getMessage('flags.target-env.description'),
}),
browser: Flags.string({
summary: messages.getMessage('flags.browser.summary'),
Expand All @@ -42,6 +41,7 @@ export default class EnvOpen extends SfCommand<OpenResult> {
};

public async run(): Promise<OpenResult> {
this.warn(messages.getMessage('warning.orgsNoLongerSupported', [this.config.bin]));
const { flags } = await this.parse(EnvOpen);
const nameOrAlias = flags['target-env'];
let url: string;
Expand All @@ -53,6 +53,7 @@ export default class EnvOpen extends SfCommand<OpenResult> {

try {
const org = await Org.create({ aliasOrUsername: nameOrAlias });
// eslint-disable-next-line sf-plugin/get-connection-with-version
const conn = org.getConnection();
await org.refreshAuth();
const authInfo = conn.getAuthInfo();
Expand Down
22 changes: 0 additions & 22 deletions src/hooks/envDisplay.ts

This file was deleted.

Loading

0 comments on commit 285c583

Please sign in to comment.