Skip to content

Commit

Permalink
feat: add column for config (#96)
Browse files Browse the repository at this point in the history
* feat: add column for config

* test: fix nuts

* test: fix nuts
  • Loading branch information
mdonnalley authored Jul 28, 2021
1 parent 8376bbc commit 4159426
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 47 deletions.
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^0.5.21",
"@salesforce/core": "v3-beta",
"@oclif/core": "^0.5.26",
"@salesforce/core": "^3.3.4",
"cli-ux": "^5.6.3",
"open": "^8.2.0",
"tslib": "^2"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "2.2.2",
"@oclif/test": "^1.2.8",
"@salesforce/cli-plugins-testkit": "^1.1.4",
"@salesforce/cli-plugins-testkit": "^1.2.0",
"@salesforce/dev-config": "^2.1.2",
"@salesforce/dev-scripts": "^0.9.18",
"@salesforce/plugin-command-reference": "^1.3.0",
"@salesforce/plugin-config": "^2.0.4",
"@salesforce/prettier-config": "^0.0.2",
"@salesforce/ts-sinon": "1.3.21",
"@types/shelljs": "^0.8.8",
Expand Down Expand Up @@ -75,7 +77,8 @@
"devPlugins": [
"@oclif/plugin-help",
"@oclif/plugin-command-snapshot",
"@salesforce/plugin-command-reference"
"@salesforce/plugin-command-reference",
"@salesforce/plugin-config"
],
"topics": {
"env": {
Expand All @@ -102,7 +105,7 @@
"test:command-reference": "./bin/dev commandreference:generate --erroronwarnings",
"test:deprecation-policy": "./bin/dev snapshot:compare",
"test:json-schema": "./bin/dev schema:compare",
"test:nuts": "yarn build && nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel",
"test:nuts": "nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel",
"version": "oclif readme"
},
"husky": {
Expand Down
15 changes: 11 additions & 4 deletions src/commands/env/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { Command, Flags } from '@oclif/core';
import { cli, Table } from 'cli-ux';
import { AuthInfo, SfOrg, Messages, SfdxError } from '@salesforce/core';
import { AuthInfo, SfOrg, Messages, SfdxError, ConfigAggregator } from '@salesforce/core';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-env', 'list');
Expand Down Expand Up @@ -51,11 +51,15 @@ export default class EnvList extends Command {
public async run(): Promise<SfOrgs> {
const { flags } = await this.parse(EnvList);

let authorizations: SfOrg[];
let authorizations: Array<SfOrg & { configs?: string[] }>;
const config = (await ConfigAggregator.create()).getConfigInfo();

try {
if (await AuthInfo.hasAuthentications()) {
authorizations = await AuthInfo.listAllAuthorizations();
for (const auth of authorizations) {
auth.configs = config.filter((c) => c.value === auth.alias || c.value === auth.username).map((c) => c.key);
}
const hasErrors = authorizations.some((auth) => !!auth.error);
const columns = {
alias: {
Expand All @@ -71,11 +75,14 @@ export default class EnvList extends Command {
oauthMethod: {
header: 'OAuth Method',
},
configs: {
header: 'Config',
get: (row: { configs?: string[] }) => (row.configs ? row.configs.join(', ') : ''),
},
} as Table.table.Columns<Partial<SfOrg>>;
if (hasErrors) {
columns.error = {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access
get: (row) => row.error ?? '',
get: (row: { error?: string }) => row.error ?? '',
} as Table.table.Columns<Partial<SfOrg>>;
}

Expand Down
10 changes: 8 additions & 2 deletions test/commands/env/display.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as path from 'path';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { ConfigAggregator } from '@salesforce/core';
import { SfdxPropertyKeys } from '@salesforce/core';
import { env } from '@salesforce/kit';
import { expect } from 'chai';

describe('env display NUTs', () => {
let session: TestSession;
let usernameOrAlias: string;
before(async () => {
env.setString('TESTKIT_EXECUTABLE_PATH', path.join(process.cwd(), 'bin', 'dev'));
session = await TestSession.create({});

usernameOrAlias = ConfigAggregator.getValue('defaultdevhubusername').value as string;
const config = execCmd<Array<{ value: string }>>(`config get ${SfdxPropertyKeys.DEFAULT_DEV_HUB_USERNAME} --json`, {
cli: 'sf',
}).jsonOutput;
usernameOrAlias = config[0].value;

if (!usernameOrAlias) throw Error('no default username set');
});
Expand Down
10 changes: 8 additions & 2 deletions test/commands/env/list.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as path from 'path';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { ConfigAggregator } from '@salesforce/core';
import { SfdxPropertyKeys } from '@salesforce/core';
import { env } from '@salesforce/kit';
import { expect } from 'chai';

describe('env list NUTs', () => {
let session: TestSession;
let usernameOrAlias: string;
before(async () => {
env.setString('TESTKIT_EXECUTABLE_PATH', path.join(process.cwd(), 'bin', 'dev'));
session = await TestSession.create({});

usernameOrAlias = ConfigAggregator.getValue('defaultdevhubusername').value as string;
const config = execCmd<Array<{ value: string }>>(`config get ${SfdxPropertyKeys.DEFAULT_DEV_HUB_USERNAME} --json`, {
cli: 'sf',
}).jsonOutput;
usernameOrAlias = config[0].value;

if (!usernameOrAlias) throw Error('no default username set');
});
Expand Down
10 changes: 8 additions & 2 deletions test/commands/env/open.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as path from 'path';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { ConfigAggregator } from '@salesforce/core';
import { SfdxPropertyKeys } from '@salesforce/core';
import { env } from '@salesforce/kit';
import { expect } from 'chai';

describe('env open NUTs', () => {
let session: TestSession;
let usernameOrAlias: string;
before(async () => {
env.setString('TESTKIT_EXECUTABLE_PATH', path.join(process.cwd(), 'bin', 'dev'));
session = await TestSession.create({});

usernameOrAlias = ConfigAggregator.getValue('defaultdevhubusername').value as string;
const config = execCmd<Array<{ value: string }>>(`config get ${SfdxPropertyKeys.DEFAULT_DEV_HUB_USERNAME} --json`, {
cli: 'sf',
}).jsonOutput;
usernameOrAlias = config[0].value;

if (!usernameOrAlias) throw Error('no default username set');
});
Expand Down
Loading

0 comments on commit 4159426

Please sign in to comment.