generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move command force to plugin-source (#451)
* fix: move command force to plugin-source @W-10847992@ * chore: add force.nuts.ts
- Loading branch information
1 parent
3325350
commit 5da7884
Showing
6 changed files
with
612 additions
and
14 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
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,89 @@ | ||
/* | ||
* 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'; | ||
import { ConfigAggregator } from '@salesforce/core'; | ||
|
||
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 apiFromConfig = ConfigAggregator.getValue('apiVersion').value as string; | ||
if (apiFromConfig) { | ||
return apiFromConfig; | ||
} | ||
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 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
Oops, something went wrong.