generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate force command from toolbelt
- Loading branch information
Showing
6 changed files
with
143 additions
and
7 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* 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 | ||
*/ | ||
|
||
// This is a doc command | ||
/* istanbul ignore file */ | ||
|
||
import { SfdxCommand } from '@salesforce/command'; | ||
import got from 'got'; | ||
import { Help } from '@oclif/plugin-help'; | ||
import * as ProxyAgent from 'proxy-agent'; | ||
import { getProxyForUrl } from 'proxy-from-env'; | ||
|
||
const getAsciiSignature = (apiVersion: string): string => ` | ||
DX DX DX | ||
DX DX DX DX DX DX DX DX DX | ||
DX DX DX DX DX DX DX DX DX DX DX DX | ||
DX DX DX DX DX DX DX DX DX DX | ||
DX DX DX DX DX DX DX DX DX DX | ||
DX DX DX DX DX DX DX DX DX DX DX | ||
DX DX DX DX DX DX DX DX | ||
DX DX DX DX DX DX | ||
DX DX DX DX | ||
DX DX DX DX | ||
DX DX DX DX | ||
DX DX DX DX | ||
DX DX DX DX | ||
DX DX DX DX | ||
DX DX DX DX | ||
DX DX DX DX | ||
DX DX DX DX | ||
DX DX DX DX DX | ||
DX DX DX DX DX DX DX DX | ||
DX DX DX DX DX DX DX | ||
DX DX DX DX DX DX DX DX | ||
DX DX DX DX DX DX DX DX DX DX DX | ||
DX DX DX DX DX DX DX DX DX | ||
DX DX DX DX | ||
DX DX DX DX DX DX | ||
DX DX DX DX DX DX v${apiVersion} | ||
DX DX DX | ||
* Salesforce CLI Release Notes: https://github.com/forcedotcom/cli/tree/main/releasenotes | ||
* Salesforce DX Setup Guide: https://sfdc.co/sfdx_setup_guide | ||
* Salesforce DX Developer Guide: https://sfdc.co/sfdx_dev_guide | ||
* Salesforce CLI Command Reference: https://sfdc.co/sfdx_cli_reference | ||
* Salesforce Extensions for VS Code: https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode | ||
`; | ||
|
||
const getCurrentApiVersion = async (): Promise<string> => { | ||
const url = 'https://mdcoverage.secure.force.com/services/apexrest/report'; | ||
return `${( | ||
JSON.parse( | ||
( | ||
await got(url, { | ||
agent: { https: ProxyAgent(getProxyForUrl(url)) }, | ||
}) | ||
).body | ||
) as { | ||
versions: { selected: number }; | ||
} | ||
).versions.selected.toString()}.0`; | ||
}; | ||
|
||
export class ForceCommand extends SfdxCommand { | ||
public static readonly hidden = true; | ||
|
||
public async run(): Promise<{ apiVersion: string }> { | ||
const apiVersion = await getCurrentApiVersion(); | ||
this.ux.log(getAsciiSignature(apiVersion)); | ||
return { apiVersion }; | ||
} | ||
|
||
// overrides the help so that it shows the help for the `force` topic and not "help" for this command | ||
protected _help(): never { | ||
const help = new Help(this.config); | ||
// We need to include force in the args for topics to be shown | ||
help.showHelp(process.argv.slice(2)); | ||
return this.exit(0); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,36 @@ | ||
/* | ||
* 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 { expect } from 'chai'; | ||
|
||
import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit'; | ||
|
||
describe('force command', () => { | ||
let session: TestSession; | ||
|
||
before(async () => { | ||
session = await TestSession.create({ | ||
project: { | ||
name: 'forceNut', | ||
}, | ||
}); | ||
}); | ||
it('returns an apiVersion in JSON', () => { | ||
const result = execCmd<{ apiVersion: string }>('force --json', { ensureExitCode: 0 }).jsonOutput.result; | ||
expect(result).to.be.an('object').that.has.all.keys('apiVersion'); | ||
expect(result.apiVersion).to.match(/^\d{2,}\.0$/); | ||
expect(parseInt(result.apiVersion, 10)).to.be.greaterThan(53); | ||
}); | ||
it('executes the cloud/links without JSON', () => { | ||
const result = execCmd('force', { ensureExitCode: 0 }).shellOutput as string; | ||
expect(result).to.include('Salesforce CLI Release Notes'); | ||
}); | ||
|
||
after(async () => { | ||
await session.clean(); | ||
}); | ||
}); |
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