generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add env display command #52
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# description | ||
|
||
Display details about a specific environment | ||
|
||
# examples | ||
|
||
sf env display -e my-scratch-org | ||
sf env display -e [email protected] | ||
|
||
# flags.environment.summary | ||
|
||
Environment name or alias to display. | ||
|
||
# error.NoResultsFound | ||
|
||
No results found | ||
|
||
# error.NoEnvFound | ||
|
||
No environment found for %s. | ||
|
||
# error.NoDefaultEnv | ||
|
||
No default environment found. Use -e or --environment to specify which env to open. | ||
|
||
# error.NoAuthsAvailable | ||
|
||
There are no authentications available. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# description | ||
|
||
List the environments you’ve created or logged into. | ||
|
||
# examples | ||
|
||
sf env list | ||
sf env list --all | ||
|
||
# flags.all.summary | ||
|
||
Show all environments, including inactive orgs. | ||
|
||
# error.NoAuthsAvailable | ||
|
||
There are no authentications available. | ||
|
||
# error.NoResultsFound | ||
|
||
No results found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$ref": "#/definitions/SfOrgs", | ||
"definitions": { | ||
"SfOrgs": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/SfOrg" | ||
} | ||
}, | ||
"SfOrg": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"$ref": "#/definitions/Optional%3CAnyJson%3E" | ||
}, | ||
"properties": { | ||
"alias": { | ||
"type": "string" | ||
}, | ||
"username": { | ||
"type": "string" | ||
}, | ||
"orgId": { | ||
"type": "string" | ||
}, | ||
"instanceUrl": { | ||
"type": "string" | ||
}, | ||
"accessToken": { | ||
"type": "string" | ||
}, | ||
"oauthMethod": { | ||
"type": "string", | ||
"enum": ["jwt", "web", "token", "unknown"] | ||
}, | ||
"error": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"Optional<AnyJson>": { | ||
"anyOf": [ | ||
{ | ||
"$ref": "#/definitions/AnyJson" | ||
}, | ||
{ | ||
"not": {} | ||
} | ||
], | ||
"description": "A union type for either the parameterized type `T` or `undefined` -- the opposite of {@link NonOptional } ." | ||
}, | ||
"AnyJson": { | ||
"anyOf": [ | ||
{ | ||
"$ref": "#/definitions/JsonPrimitive" | ||
}, | ||
{ | ||
"$ref": "#/definitions/JsonCollection" | ||
} | ||
], | ||
"description": "Any valid JSON value." | ||
}, | ||
"JsonPrimitive": { | ||
"type": ["null", "boolean", "number", "string"], | ||
"description": "Any valid JSON primitive value." | ||
}, | ||
"JsonCollection": { | ||
"anyOf": [ | ||
{ | ||
"$ref": "#/definitions/JsonMap" | ||
}, | ||
{ | ||
"$ref": "#/definitions/JsonArray" | ||
} | ||
], | ||
"description": "Any valid JSON collection value." | ||
}, | ||
"JsonMap": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"$ref": "#/definitions/Optional%3CAnyJson%3E" | ||
}, | ||
"properties": {}, | ||
"description": "Any JSON-compatible object." | ||
}, | ||
"JsonArray": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/AnyJson" | ||
}, | ||
"description": "Any JSON-compatible array." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) 2021, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { EOL } from 'os'; | ||
|
||
import { Command, flags } from '@oclif/command'; | ||
import { cli } from 'cli-ux'; | ||
import { AuthInfo, SfOrg, Messages, SfdxError } from '@salesforce/core'; | ||
|
||
Messages.importMessagesDirectory(__dirname); | ||
const messages = Messages.loadMessages('@salesforce/plugin-env', 'display'); | ||
|
||
export type SfOrgs = SfOrg[]; | ||
|
||
export default class EnvDisplay extends Command { | ||
public static readonly description = messages.getMessage('description'); | ||
public static readonly examples = messages.getMessage('examples').split(EOL); | ||
public static flags = { | ||
environment: flags.string({ | ||
char: 'e', | ||
description: messages.getMessage('flags.environment.summary'), | ||
}), | ||
}; | ||
|
||
public flags: { | ||
environment: string; | ||
}; | ||
|
||
// TODO: Change SfOrg type to a more generalized auth type once we have Functions envs integrated. | ||
|
||
public async run(): Promise<SfOrgs> { | ||
this.flags = this.parse(EnvDisplay).flags; | ||
|
||
let authorizations: SfOrg[]; | ||
let foundAuthorization: SfOrg; | ||
|
||
try { | ||
if (await AuthInfo.hasAuthentications()) { | ||
authorizations = await AuthInfo.listAllAuthorizations(); | ||
|
||
if (!this.flags.environment) { | ||
// TODO this should be retrieved from sf config once we have those commands. If not found, still throw. | ||
throw messages.createError('error.NoDefaultEnv'); | ||
} | ||
|
||
foundAuthorization = authorizations.filter((auth) => auth.username === this.flags.environment)[0]; | ||
if (!foundAuthorization) { | ||
foundAuthorization = authorizations.filter((auth) => auth.alias === this.flags.environment)[0]; | ||
} | ||
|
||
if (foundAuthorization) { | ||
const columns = { | ||
key: {}, | ||
value: {}, | ||
}; | ||
|
||
cli.table( | ||
Object.keys(foundAuthorization).map((key, i) => ({ key, value: Object.values(foundAuthorization)[i] })), | ||
columns | ||
); | ||
} else { | ||
throw new SfdxError(messages.getMessage('error.NoEnvFound', [this.flags.environment])); | ||
} | ||
} else { | ||
throw messages.createError('error.NoAuthsAvailable'); | ||
} | ||
} catch (error) { | ||
const err = error as SfdxError; | ||
cli.log(messages.getMessage('error.NoResultsFound')); | ||
cli.error(err); | ||
} | ||
|
||
return authorizations; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should have
AnyJson
or any of these types in the return typesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comes from the return type being
SfOrgs
which isSfOrg[]
which has a union withSfEntry
which equalsJsonMap
which extendsDictionary<AnyJson>
.env display
orenv list
don't do anything withAnyJson
explicitly.