Skip to content

Commit

Permalink
feat: use SfCommand (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley authored Sep 10, 2021
1 parent 6c82a93 commit 4182bcc
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 75 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"bugs": "https://github.com/salesforcecli/cli/issues",
"dependencies": {
"@oclif/core": "^0.5.35",
"@salesforce/command": "^4.1.0",
"@salesforce/core": "3.4.5",
"@salesforce/sf-plugins-core": "^0.0.16",
"change-case": "^4.1.2",
Expand All @@ -16,11 +17,11 @@
"devDependencies": {
"@oclif/plugin-command-snapshot": "2.2.2",
"@oclif/test": "^1.2.8",
"@salesforce/cli-plugins-testkit": "^1.2.1",
"@salesforce/cli-plugins-testkit": "^1.4.1",
"@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/plugin-command-reference": "^2.0.6",
"@salesforce/plugin-config": "^2.2.0",
"@salesforce/prettier-config": "^0.0.2",
"@salesforce/ts-sinon": "1.3.21",
"@types/shelljs": "^0.8.8",
Expand Down
5 changes: 3 additions & 2 deletions src/commands/env/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { Command, Flags } from '@oclif/core';
import { Flags } from '@oclif/core';
import { SfCommand } from '@salesforce/command';
import { cli } from 'cli-ux';
import { Messages, SfdxError } from '@salesforce/core';
import { SfHook, JsonObject } from '@salesforce/sf-plugins-core';
Expand All @@ -14,7 +15,7 @@ import { toKey, toValue } from '../../utils';
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-env', 'display');

export default class EnvDisplay extends Command {
export default class EnvDisplay extends SfCommand<JsonObject> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
Expand Down
5 changes: 3 additions & 2 deletions src/commands/env/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { Command, Flags } from '@oclif/core';
import { Flags } from '@oclif/core';
import { SfCommand } from '@salesforce/command';
import { cli } from 'cli-ux';
import { Messages, SfdxError } from '@salesforce/core';
import { JsonObject, SfHook } from '@salesforce/sf-plugins-core';
Expand All @@ -16,7 +17,7 @@ const messages = Messages.loadMessages('@salesforce/plugin-env', 'list');

export type Environments = JsonObject[];

export default class EnvList extends Command {
export default class EnvList extends SfCommand<Environments> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
Expand Down
5 changes: 3 additions & 2 deletions src/commands/env/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import { URL } from 'url';
import { Command, Flags } from '@oclif/core';
import { Flags } from '@oclif/core';
import { SfCommand } from '@salesforce/command';
import { Logger, Messages, Org, SfdxError } from '@salesforce/core';
import * as open from 'open';
import type { Options } from 'open';
Expand All @@ -19,7 +20,7 @@ type Environment = { name: string; openUrl: string };

export type OpenResult = { url: string };

export default class EnvOpen extends Command {
export default class EnvOpen extends SfCommand<OpenResult> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
Expand Down
6 changes: 3 additions & 3 deletions test/commands/env/display.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

Expand All @@ -18,9 +18,9 @@ describe('env display NUTs', () => {
env.setString('TESTKIT_EXECUTABLE_PATH', path.join(process.cwd(), 'bin', 'dev'));
session = await TestSession.create({});

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

if (!usernameOrAlias) throw Error('no default username set');
Expand Down
8 changes: 4 additions & 4 deletions test/commands/env/display.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ describe('display unit tests', () => {
.stdout()
.command(['env:display', '--target-env', ORG.username, '--json'])
.it('should display requested username with json output', (ctx) => {
const actual = JSON.parse(ctx.stdout) as OrgAuthorization;
expect(actual).to.be.deep.equal(ORG);
const actual = JSON.parse(ctx.stdout) as { result: OrgAuthorization };
expect(actual.result).to.be.deep.equal(ORG);
});

test
Expand All @@ -46,8 +46,8 @@ describe('display unit tests', () => {
.stdout()
.command(['env:display', '--target-env', ORG.aliases[0], '--json'])
.it('should display requested alias with json output', (ctx) => {
const actual = JSON.parse(ctx.stdout) as OrgAuthorization;
expect(actual).to.be.deep.equal(ORG);
const actual = JSON.parse(ctx.stdout) as { result: OrgAuthorization };
expect(actual.result).to.be.deep.equal(ORG);
});

test
Expand Down
6 changes: 3 additions & 3 deletions test/commands/env/list.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

Expand All @@ -18,9 +18,9 @@ describe('env list NUTs', () => {
env.setString('TESTKIT_EXECUTABLE_PATH', path.join(process.cwd(), 'bin', 'dev'));
session = await TestSession.create({});

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

if (!usernameOrAlias) throw Error('no default username set');
Expand Down
4 changes: 2 additions & 2 deletions test/commands/env/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ describe('list unit tests', () => {
.stdout()
.command(['env:list', '--json'])
.it('should list active orgs with json output', (ctx) => {
const sfOrgs = JSON.parse(ctx.stdout) as OrgAuthorization[];
expect(sfOrgs).to.be.deep.equal(expectedSfOrgs);
const sfOrgs = JSON.parse(ctx.stdout) as { result: OrgAuthorization[] };
expect(sfOrgs.result).to.be.deep.equal(expectedSfOrgs);
});

test
Expand Down
6 changes: 3 additions & 3 deletions test/commands/env/open.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

Expand All @@ -18,9 +18,9 @@ describe('env open NUTs', () => {
env.setString('TESTKIT_EXECUTABLE_PATH', path.join(process.cwd(), 'bin', 'dev'));
session = await TestSession.create({});

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

if (!usernameOrAlias) throw Error('no default username set');
Expand Down
22 changes: 5 additions & 17 deletions test/commands/env/open.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
/*
* Copyright (c) 2020, 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
*/
/*
* Copyright (c) 2020, 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
*/
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
Expand Down Expand Up @@ -70,11 +58,11 @@ describe('open unit tests', () => {
])
.it('should open environment with redirect path with json output', (ctx) => {
const stdout = ctx.stdout;
const url = JSON.parse(stdout) as OpenResult;
const { result } = JSON.parse(stdout) as { result: OpenResult };
const urlStartRegEx = new RegExp(`^${expectedSfOrgs[0].instanceUrl}.*`);
const urlEndRegEx = new RegExp(`.*[?,&]retURL=${encodeURIComponent('/foo/bar/baz/')}`);
expect(url.url).match(urlStartRegEx);
expect(url.url).match(urlEndRegEx);
expect(result.url).match(urlStartRegEx);
expect(result.url).match(urlEndRegEx);
});
test
.stub(Connection.prototype, 'getAuthInfo', (): AuthInfo => {
Expand All @@ -100,8 +88,8 @@ describe('open unit tests', () => {
.command(['env:open', '--target-env', expectedSfOrgs[0].username, '--json'])
.it('should open requested environment', (ctx) => {
const stdout = ctx.stdout;
const url = JSON.parse(stdout) as OpenResult;
expect(url.url).to.be.equal(expectedSfOrgs[0].instanceUrl);
const { result } = JSON.parse(stdout) as { result: OpenResult };
expect(result.url).to.be.equal(expectedSfOrgs[0].instanceUrl);
});
test
.stdout()
Expand Down
70 changes: 36 additions & 34 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@
supports-color "^5.4.0"
tslib "^1"

"@oclif/command@^1.5.10", "@oclif/command@^1.5.13", "@oclif/command@^1.5.17", "@oclif/command@^1.5.19", "@oclif/command@^1.5.20", "@oclif/command@^1.6", "@oclif/command@^1.6.0", "@oclif/command@^1.8.0":
"@oclif/command@^1.5.10", "@oclif/command@^1.5.13", "@oclif/command@^1.5.17", "@oclif/command@^1.5.20", "@oclif/command@^1.6", "@oclif/command@^1.6.0", "@oclif/command@^1.8.0":
version "1.8.0"
resolved "https://registry.yarnpkg.com/@oclif/command/-/command-1.8.0.tgz#c1a499b10d26e9d1a611190a81005589accbb339"
integrity sha512-5vwpq6kbvwkQwKqAoOU3L72GZ3Ta8RRrewKj9OJRolx28KLJJ8Dg9Rf7obRwt5jQA9bkYd8gqzMTrI7H3xLfaw==
Expand All @@ -468,7 +468,7 @@
debug "^4.1.1"
semver "^7.3.2"

"@oclif/config@^1", "@oclif/config@^1.12.6", "@oclif/config@^1.12.8", "@oclif/config@^1.14.0", "@oclif/config@^1.15.1", "@oclif/config@^1.17.0":
"@oclif/config@^1", "@oclif/config@^1.12.6", "@oclif/config@^1.12.8", "@oclif/config@^1.15.1", "@oclif/config@^1.17.0":
version "1.17.0"
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.17.0.tgz#ba8639118633102a7e481760c50054623d09fcab"
integrity sha512-Lmfuf6ubjQ4ifC/9bz1fSCHc6F6E653oyaRXxg+lgT4+bYf9bk+nqrUpAbrXyABkCqgIBiFr3J4zR/kiFdE1PA==
Expand All @@ -480,7 +480,7 @@
is-wsl "^2.1.1"
tslib "^2.0.0"

"@oclif/core@^0.5.19", "@oclif/core@^0.5.26":
"@oclif/core@^0.5.19":
version "0.5.27"
resolved "https://registry.yarnpkg.com/@oclif/core/-/core-0.5.27.tgz#d06630d915c746076d34473d6e4772580811dd72"
integrity sha512-BfS4REDHx1mr7RnitYkznIQ5fzLBCf0fRbyB/dqgMNPhAVsdzQpjobn5x+dMdcsLhO+2iXisfoMl+x0j9AB9bw==
Expand All @@ -503,7 +503,7 @@
widest-line "^3.1.0"
wrap-ansi "^7.0.0"

"@oclif/core@^0.5.35":
"@oclif/core@^0.5.31", "@oclif/core@^0.5.34", "@oclif/core@^0.5.35":
version "0.5.35"
resolved "https://registry.npmjs.org/@oclif/core/-/core-0.5.35.tgz#20d6dd2be4c78449227c2912aa23e4d451d7add5"
integrity sha512-5nTd+lOcDh1QPa9mM74qFChmApp5oHnP3EqYGYwqhfA3ad4qIfyYEn8pKxf0MlrYoPA8j2PrmceuRZThstKssA==
Expand Down Expand Up @@ -675,10 +675,10 @@
mv "~2"
safe-json-stringify "~1"

"@salesforce/cli-plugins-testkit@^1.2.1":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@salesforce/cli-plugins-testkit/-/cli-plugins-testkit-1.3.3.tgz#fffc366d4c370386ba5ec0a21671863840af3cbf"
integrity sha512-e5f9Ttfxu8yVCInjjjnR52t3ajNVC6cxa6bsfmLn3uiiyH/6CMjIbr9f3/Y8f2QNdbS4el9wRwkxurpm0N9G0Q==
"@salesforce/cli-plugins-testkit@^1.4.1":
version "1.4.1"
resolved "https://registry.npmjs.org/@salesforce/cli-plugins-testkit/-/cli-plugins-testkit-1.4.1.tgz#b1dcbf64a4d33c29b4724d8a49d1c0f4757ca2b1"
integrity sha512-FAeSwJpJfJZePtIFw0V/rg6WjRxm29vtdIslTdVlO5jfNY9QxK5/iiuq0zBhe53GPdbAa1RMQTcFhqQd3r0pag==
dependencies:
"@salesforce/core" "^2.24.0"
"@salesforce/kit" "^1.5.13"
Expand All @@ -688,12 +688,13 @@
shelljs "^0.8.4"
strip-ansi "6.0.0"

"@salesforce/command@^3.0.0":
version "3.1.3"
resolved "https://registry.yarnpkg.com/@salesforce/command/-/command-3.1.3.tgz#d72ed2bc516ce7fea1151576a997b45fd1752d26"
integrity sha512-Yg9lhl3ghwPN7WwqFmgfWIn6i7vz43WTpEsYsChz80bKORlVbDvhwPZQUj0XTv3DKDnPZVU8FFIDsrLSOa9G1A==
"@salesforce/command@^4.0.5", "@salesforce/command@^4.1.0":
version "4.1.0"
resolved "https://registry.npmjs.org/@salesforce/command/-/command-4.1.0.tgz#0522d2a6f98ecda2ab7f3431fa6fdb053cd4d78a"
integrity sha512-zfLEoY6cLT21luSNFISQ21yWxi7hAAtGLAGeV0ciJ9tSF+Fy+twZAciSWR47GCRBa54sFQwZbHoVUAx2KPXi2Q==
dependencies:
"@oclif/command" "^1.5.17"
"@oclif/core" "^0.5.34"
"@oclif/errors" "^1.2.2"
"@oclif/parser" "^3.8.3"
"@oclif/plugin-help" "^2.2.0"
Expand All @@ -704,10 +705,10 @@
chalk "^2.4.2"
cli-ux "^4.9.3"

"@salesforce/core@3.3.5":
version "3.3.5"
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.3.5.tgz#caa40e618c7c53d158336ce2d9a292d340982c0b"
integrity sha512-PwhErCgZVj8ho0svqL37XCWWngY7m58+28p+Lxm451uZ11NywrY7cgP6k7WE6vs5js81lBTvToSjesEWAZKPKg==
"@salesforce/core@3.4.2":
version "3.4.2"
resolved "https://registry.npmjs.org/@salesforce/core/-/core-3.4.2.tgz#fd7ecc719d40d1ebca4b7665a031bbc06fa0f939"
integrity sha512-7mRiFvwLvEPOqA0hIaevrSGSP9G6y9uf1eJaSl83JVeusnmCFg6KgXlbabcrCJPedl6PX8pUsZS4sClfWVU6Gw==
dependencies:
"@salesforce/bunyan" "^2.0.0"
"@salesforce/kit" "^1.5.8"
Expand Down Expand Up @@ -813,35 +814,36 @@
typescript "^4.1.3"
xunit-file "^1.0.0"

"@salesforce/kit@^1.2.2", "@salesforce/kit@^1.5.0", "@salesforce/kit@^1.5.13", "@salesforce/kit@^1.5.8":
"@salesforce/kit@^1.2.2", "@salesforce/kit@^1.5.0", "@salesforce/kit@^1.5.13", "@salesforce/kit@^1.5.17", "@salesforce/kit@^1.5.8":
version "1.5.17"
resolved "https://registry.npmjs.org/@salesforce/kit/-/kit-1.5.17.tgz#4fd9c50ba2e072c50d319654f86f86808c544795"
integrity sha512-Uuh+v7WPSo+L21moVprl+jbDTl3ndmcJM5et/vFLZW4ur6CCJCJSoReM9ttF1qZuQskyCyhVZo6/aMZrVUe+rQ==
dependencies:
"@salesforce/ts-types" "^1.5.20"
tslib "^2.2.0"

"@salesforce/plugin-command-reference@^1.3.0":
version "1.3.14"
resolved "https://registry.yarnpkg.com/@salesforce/plugin-command-reference/-/plugin-command-reference-1.3.14.tgz#efc0ad6e635760ff52bccdd7bf91eca7510dd4ab"
integrity sha512-YXlcXoGCwVpQIrMSNEXJ9RwlBu4oQCyP5fhDe5dL2cl5sQQwMhfQWzDY05wcjSmM7snYENHbudKGAXm9nk4+kg==
"@salesforce/plugin-command-reference@^2.0.6":
version "2.0.6"
resolved "https://registry.npmjs.org/@salesforce/plugin-command-reference/-/plugin-command-reference-2.0.6.tgz#9fd0b4420e561540e70e297664e92ddb6a46d798"
integrity sha512-zm65EN88iN/u8RRVK1qGtAGcE4mYDuK6sLNDi014wHOdT3eXNDJ6s9oIjvAi8WrWolzblP4QtfsyQbtZP+oRuQ==
dependencies:
"@oclif/command" "^1.5.19"
"@oclif/config" "^1.14.0"
"@oclif/errors" "^1.2.2"
"@salesforce/command" "^3.0.0"
"@oclif/core" "^0.5.34"
"@salesforce/command" "^4.0.5"
"@salesforce/core" "^2.2.0"
"@salesforce/kit" "^1.5.17"
"@salesforce/ts-types" "^1.5.20"
chalk "^3.0.0"
handlebars "^4.7.3"
tslib "^1"
handlebars "^4.7.7"
tslib "^2"

"@salesforce/plugin-config@^2.0.4":
version "2.0.7"
resolved "https://registry.yarnpkg.com/@salesforce/plugin-config/-/plugin-config-2.0.7.tgz#837f088cfa2479017696709e2fcf127d3369da98"
integrity sha512-409PyGfBzjWOw3g3vCXGJcFNuQUTW9rFxE9OFBuiRTGRxyIk6RwJTL3Oawi+bv0EInIeYWtzkSoelVt1etokoA==
"@salesforce/plugin-config@^2.2.0":
version "2.2.0"
resolved "https://registry.npmjs.org/@salesforce/plugin-config/-/plugin-config-2.2.0.tgz#fb0a4234062efb3ca03052fe40d5799bced01539"
integrity sha512-7BTPn22rrO8CVASXHedzKT1WfaqR4oJ3hUXvbRXJ9NAB+U+xhJZDY05qiYJ+210Px4aGHVz1jS5RzoVpXKwszQ==
dependencies:
"@oclif/core" "^0.5.26"
"@salesforce/core" "3.3.5"
"@oclif/core" "^0.5.31"
"@salesforce/command" "^4.1.0"
"@salesforce/core" "3.4.2"
chalk "^4.1.1"
cli-ux "^5.6.3"
tslib "^2"
Expand Down Expand Up @@ -3980,7 +3982,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e"
integrity sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==

handlebars@^4.7.3, handlebars@^4.7.6:
handlebars@^4.7.6, handlebars@^4.7.7:
version "4.7.7"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.7.tgz#9ce33416aad02dbd6c8fafa8240d5d98004945a1"
integrity sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA==
Expand Down

0 comments on commit 4182bcc

Please sign in to comment.