Skip to content

Commit

Permalink
fix: only show active orgs by default
Browse files Browse the repository at this point in the history
  • Loading branch information
RodEsp committed Aug 10, 2021
1 parent 92b8856 commit 6ac5bf5
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 37 deletions.
2 changes: 1 addition & 1 deletion command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"command": "env:list",
"plugin": "@salesforce/plugin-env",
"flags": ["columns", "csv", "extended", "filter", "json", "no-header", "no-truncate", "output", "sort"]
"flags": ["all", "columns", "csv", "extended", "filter", "json", "no-header", "no-truncate", "output", "sort"]
},
{
"command": "env:open",
Expand Down
16 changes: 12 additions & 4 deletions messages/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ List the environments you’ve created or logged into.

# description

The command displays only active environments. For orgs, active means unexpired scratch orgs and orgs you’re currently logged into.
The command displays only active environments. For orgs, active means unexpired scratch orgs and orgs you’re currently logged into.

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 get their own table.

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. The table also displays the default environment for each type, the instance URL, and how you authorized (logged into) the org, either using a web browser or JWT.

Use the table-manipulation flags, such as --filter and --sort, to change how the data is displayed.
Use the table-manipulation flags, such as --filter and --sort, to change how the data is displayed.

Run "sf env display" to view details about a specific environment.

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

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

- List all environments:

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

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

<%= config.bin %> <%= command.id %> --filter "OAuth Method=web"
Expand All @@ -31,11 +35,15 @@ Run "sf env display" to view details about a specific environment.
- Don't truncate the displayed output:

<%= config.bin %> <%= command.id %> --no-truncate

- Display only the table data, not the headers, in comma-separated value (csv) format:

<%= config.bin %> <%= command.id %> --csv --no-header

# flags.all.summary

Show all envs regardless of status.

# flags.extended.summary

Show extra columns.
Expand All @@ -62,7 +70,7 @@ Don't truncate output to fit screen.

# flags.output.summary

Format in which to display the output.
Format in which to display the output.

# flags.sort.summary

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^0.5.26",
"@oclif/core": "^0.5.29",
"@salesforce/core": "3.3.11",
"cli-ux": "^5.6.3",
"open": "^8.2.0",
Expand Down
29 changes: 17 additions & 12 deletions schemas/env-display.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
},
"oauthMethod": {
"type": "string",
"enum": [
"jwt",
"web",
"token",
"unknown"
]
"enum": ["jwt", "web", "token", "unknown"]
},
"aliases": {
"anyOf": [
Expand Down Expand Up @@ -49,6 +44,9 @@
"isScratchOrg": {
"type": "boolean"
},
"isDevHub": {
"type": "boolean"
},
"instanceUrl": {
"type": "string"
},
Expand All @@ -57,14 +55,21 @@
},
"error": {
"type": "string"
},
"isExpired": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "string",
"const": "unknown"
}
]
}
},
"required": [
"orgId",
"username",
"oauthMethod"
],
"required": ["orgId", "username", "oauthMethod", "isExpired"],
"additionalProperties": false
}
}
}
}
29 changes: 17 additions & 12 deletions schemas/env-list.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
},
"oauthMethod": {
"type": "string",
"enum": [
"jwt",
"web",
"token",
"unknown"
]
"enum": ["jwt", "web", "token", "unknown"]
},
"aliases": {
"anyOf": [
Expand Down Expand Up @@ -55,6 +50,9 @@
"isScratchOrg": {
"type": "boolean"
},
"isDevHub": {
"type": "boolean"
},
"instanceUrl": {
"type": "string"
},
Expand All @@ -63,14 +61,21 @@
},
"error": {
"type": "string"
},
"isExpired": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "string",
"const": "unknown"
}
]
}
},
"required": [
"orgId",
"username",
"oauthMethod"
],
"required": ["orgId", "username", "oauthMethod", "isExpired"],
"additionalProperties": false
}
}
}
}
26 changes: 19 additions & 7 deletions src/commands/env/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ export default class EnvList extends Command {
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
public static flags = {
extended: Flags.boolean({
char: 'x',
summary: messages.getMessage('flags.extended.summary'),
hidden: true,
all: Flags.boolean({
summary: messages.getMessage('flags.all.summary'),
char: 'a',
}),
columns: Flags.string({
summary: messages.getMessage('flags.columns.summary'),
Expand All @@ -31,6 +30,11 @@ export default class EnvList extends Command {
csv: Flags.boolean({
summary: messages.getMessage('flags.csv.summary'),
}),
extended: Flags.boolean({
char: 'x',
summary: messages.getMessage('flags.extended.summary'),
hidden: true,
}),
filter: Flags.string({
summary: messages.getMessage('flags.filter.summary'),
}),
Expand All @@ -49,11 +53,12 @@ export default class EnvList extends Command {
}),
};
private flags!: {
json: boolean;
extended: boolean;
all: boolean;
columns: string[];
csv: boolean;
extended: boolean;
filter: string;
json: boolean;
'no-header': boolean;
'no-truncate': boolean;
output: string;
Expand All @@ -78,7 +83,14 @@ export default class EnvList extends Command {
}

private async handleSfOrgs(): Promise<OrgAuthorization[]> {
const auths = await AuthInfo.listAllAuthorizations();
let auths: OrgAuthorization[];

if (this.flags.all) {
auths = await AuthInfo.listAllAuthorizations();
} else {
// Only get active auths
auths = await AuthInfo.listAllAuthorizations((auth) => auth.isExpired !== false);
}

const grouped = {
nonScratchOrgs: [] as OrgAuthorization[],
Expand Down
23 changes: 23 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,29 @@
widest-line "^3.1.0"
wrap-ansi "^7.0.0"

"@oclif/core@^0.5.29":
version "0.5.29"
resolved "https://registry.yarnpkg.com/@oclif/core/-/core-0.5.29.tgz#97d02f6f06d94f457d494d6cb526d6bbcb37f7ec"
integrity sha512-v5MMxeTgEKbVcEl7D3jsTVL8Wy3lLTDj0KHX7cOmI751yfjdAOqy9frHQ6IXssxubDkBW6sXzbYN9Bw12zsBqg==
dependencies:
"@oclif/linewrap" "^1.0.0"
chalk "^4.1.0"
clean-stack "^3.0.0"
cli-ux "^5.1.0"
debug "^4.1.1"
fs-extra "^9.0.1"
get-package-type "^0.1.0"
globby "^11.0.1"
indent-string "^4.0.0"
is-wsl "^2.1.1"
lodash.template "^4.4.0"
semver "^7.3.2"
string-width "^4.2.0"
strip-ansi "^6.0.0"
tslib "^2.0.0"
widest-line "^3.1.0"
wrap-ansi "^7.0.0"

"@oclif/dev-cli@^1":
version "1.26.0"
resolved "https://registry.yarnpkg.com/@oclif/dev-cli/-/dev-cli-1.26.0.tgz#e3ec294b362c010ffc8948003d3770955c7951fd"
Expand Down

0 comments on commit 6ac5bf5

Please sign in to comment.