Skip to content
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

fix: org create command to sf style #5295

Merged
merged 11 commits into from
Jan 4, 2024
8 changes: 4 additions & 4 deletions packages/salesforcedx-test-utils-vscode/src/orgUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export const createScratchOrg = async (
);
const execution = new CliCommandExecutor(
new SfdxCommandBuilder()
.withArg('force:org:create')
.withFlag('--definitionfile', `${scratchDefFilePath}`)
.withArg('--setdefaultusername')
.withJson()
.withArg('org:create:scratch')
.withFlag('--definition-file', `${scratchDefFilePath}`)
.withArg('--set-default')
.withJson(false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we want JSON anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we want it, the false is just to evaluate the addition of --loglevel

.build(),
{ cwd: path.join(process.cwd(), projectName) }
).execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ export class CommandBuilder {
return this;
}

public withJson(): CommandBuilder {
public withJson(logLevel: boolean = true): CommandBuilder {
this.args.push('--json');
this.args.push('--loglevel', 'fatal');
if (logLevel) {
this.args.push('--loglevel', 'fatal');
}
Comment on lines 60 to +65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are now using the SF_LOG_LEVEL environment variable instead of the deprecated --loglevel flag, is this change necessary? Or is it ok to just take out the --loglevel flag entirely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that flag is still used in other commands, so I'd keep it until the very last moment when we actually change from sfdx to sf or when no other commands are left to be transitioned

return this;
}

Expand Down
11 changes: 8 additions & 3 deletions packages/salesforcedx-vscode-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
"when": "sfdx:project_opened"
},
{
"command": "sfdx.force.org.create",
"command": "sfdx.org.create",
"when": "sfdx:project_opened"
},
{
Expand Down Expand Up @@ -647,8 +647,8 @@
"title": "%force_open_documentation_text%"
},
{
"command": "sfdx.force.org.create",
"title": "%force_org_create_default_scratch_org_text%"
"command": "sfdx.org.create",
"title": "%org_create_default_scratch_org_text%"
},
{
"command": "sfdx.org.open",
Expand Down Expand Up @@ -973,6 +973,11 @@
"type": "string",
"default": null,
"description": "%node_extra_ca_certs_description%"
},
"salesforcedx-vscode-core.SF_LOG_LEVEL": {
"type": "string",
"default": null,
"description": "%sf_log_level_description%"
}
}
},
Expand Down
5 changes: 3 additions & 2 deletions packages/salesforcedx-vscode-core/package.nls.ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"force_auth_access_token_authorize_org_text": "SFDX: Authorize an Org using Session ID",
"org_logout_all_text": "SFDX: すべての認証済み組織からログアウト",
"org_logout_default_text": "SFDX: Log Out from Default Org",
"force_org_create_default_scratch_org_text": "SFDX: デフォルトのスクラッチ組織を作成...",
"org_create_default_scratch_org_text": "SFDX: デフォルトのスクラッチ組織を作成...",
"org_open_default_scratch_org_text": "SFDX: デフォルトの組織を開く",
"force_source_pull_default_org_text": "SFDX: デフォルトのスクラッチ組織からソースをプル",
"force_source_pull_force_default_org_text": "SFDX: デフォルトのスクラッチ組織からソースをプルして競合を上書き",
Expand Down Expand Up @@ -68,6 +68,7 @@
"force_diff_folder_against_org": "SFDX: フォルダと組織の差分を表示",
"force_analytics_template_create_text": "SFDX: サンプルの Analytics テンプレートを作成",
"force_sobjects_refresh": "SFDX: SObject 定義を更新",
"node_extra_ca_certs": "NODE_EXTRA_CA_CERTS CLI environment variable value",
"node_extra_ca_certs_description": "NODE_EXTRA_CA_CERTS CLI environment variable value",
"sf_log_level_description": "SF_LOG_LEVEL CLI environment variable value",
"enable_sobject_refresh_on_startup_description": "プロジェクトに sObject 定義がない場合、拡張機能が有効化される際に自動的に sObject 定義を更新するかどうかを指定します。"
}
3 changes: 2 additions & 1 deletion packages/salesforcedx-vscode-core/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"org_logout_all_text": "SFDX: Log Out from All Authorized Orgs",
"org_logout_default_text": "SFDX: Log Out from Default Org",
"force_open_documentation_text": "SFDX: Open Documentation",
"force_org_create_default_scratch_org_text": "SFDX: Create a Default Scratch Org...",
"org_create_default_scratch_org_text": "SFDX: Create a Default Scratch Org...",
"org_open_default_scratch_org_text": "SFDX: Open Default Org",
"force_source_pull_default_org_text": "SFDX: Pull Source from Default Org",
"force_source_pull_force_default_org_text": "SFDX: Pull Source from Default Org and Override Conflicts",
Expand Down Expand Up @@ -75,6 +75,7 @@
"force_analytics_template_create_text": "SFDX: Create Sample Analytics Template",
"force_sobjects_refresh": "SFDX: Refresh SObject Definitions",
"node_extra_ca_certs_description": "NODE_EXTRA_CA_CERTS CLI environment variable value",
"sf_log_level_description": "SF_LOG_LEVEL CLI environment variable value",
"enable_sobject_refresh_on_startup_description": "If a project has no sObject definitions, specifies whether to automatically refresh sObject definitions on extension activation (true) or not (false).",
"force_launch_apex_replay_debugger_with_current_file": "SFDX: Launch Apex Replay Debugger with Current File",
"setting_clear_output_tab_description": "When a new command is run, clear the output content from the previous command."
Expand Down
6 changes: 1 addition & 5 deletions packages/salesforcedx-vscode-core/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ export {
forceListMetadata
} from './forceListMetadata';
export { forceOpenDocumentation } from './forceOpenDocumentation';
export {
AliasGatherer,
ForceOrgCreateExecutor,
forceOrgCreate
} from './forceOrgCreate';
export { AliasGatherer, OrgCreateExecutor, orgCreate } from './orgCreate';
export { forceOrgDelete } from './forceOrgDelete';
export {
ForcePackageInstallExecutor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,21 @@ import {
export const DEFAULT_ALIAS = 'vscodeScratchOrg';
export const DEFAULT_EXPIRATION_DAYS = '7';

export class ForceOrgCreateExecutor extends SfdxCommandletExecutor<
AliasAndFileSelection
> {
export class OrgCreateExecutor extends SfdxCommandletExecutor<AliasAndFileSelection> {
public build(data: AliasAndFileSelection): Command {
const selectionPath = path.relative(
workspaceUtils.getRootWorkspacePath(), // this is safe because of workspaceChecker
data.file
);
return new SfdxCommandBuilder()
.withDescription(
nls.localize('force_org_create_default_scratch_org_text')
)
.withArg('force:org:create')
.withFlag('-f', `${selectionPath}`)
.withFlag('--setalias', data.alias)
.withFlag('--durationdays', data.expirationDays)
.withArg('--setdefaultusername')
.withLogName('force_org_create_default_scratch_org')
.withJson()
.withDescription(nls.localize('org_create_default_scratch_org_text'))
.withArg('org:create:scratch')
.withFlag('--definition-file', `${selectionPath}`)
.withFlag('--alias', data.alias)
.withFlag('--duration-days', data.expirationDays)
.withArg('--set-default')
.withLogName('org_create_default_scratch_org')
.withJson(false)
.build();
}

Expand All @@ -68,7 +64,7 @@ export class ForceOrgCreateExecutor extends SfdxCommandletExecutor<
const cancellationToken = cancellationTokenSource.token;
const execution = new CliCommandExecutor(this.build(response.data), {
cwd: workspaceUtils.getRootWorkspacePath(),
env: { SFDX_JSON_TO_STDOUT: 'true' }
env: { SF_JSON_TO_STDOUT: 'true' }
}).execute(cancellationToken);

channelService.streamCommandStartStop(execution);
Expand All @@ -91,7 +87,8 @@ export class ForceOrgCreateExecutor extends SfdxCommandletExecutor<
OrgType.SourceTracked
);
} else {
const errorResponse = createParser.getResult() as OrgCreateErrorResult;
const errorResponse =
createParser.getResult() as OrgCreateErrorResult;
if (errorResponse) {
channelService.appendLine(errorResponse.message);
telemetryService.sendException(
Expand All @@ -102,11 +99,11 @@ export class ForceOrgCreateExecutor extends SfdxCommandletExecutor<
}
} catch (err) {
channelService.appendLine(
nls.localize('force_org_create_result_parsing_error')
nls.localize('org_create_result_parsing_error')
);
channelService.appendLine(err);
telemetryService.sendException(
'force_org_create',
'org_create_scratch',
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`Error while parsing org create response ${err}`
);
Expand Down Expand Up @@ -197,11 +194,11 @@ const parameterGatherer = new CompositeParametersGatherer(
new AliasGatherer()
);

export async function forceOrgCreate() {
export async function orgCreate() {
const commandlet = new SfdxCommandlet(
preconditionChecker,
parameterGatherer,
new ForceOrgCreateExecutor()
new OrgCreateExecutor()
);
await commandlet.run();
}
1 change: 1 addition & 0 deletions packages/salesforcedx-vscode-core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const ENABLE_DEPLOY_AND_RETRIEVE_FOR_SOURCE_TRACKED_ORGS =
export const ENABLE_SOURCE_TRACKING_FOR_DEPLOY_RETRIEVE =
'experimental.enableSourceTrackingForDeployAndRetrieve';
export const ENV_NODE_EXTRA_CA_CERTS = 'NODE_EXTRA_CA_CERTS';
export const ENV_SF_LOG_LEVEL = 'SF_LOG_LEVEL';
export const CLI = {
ORG_LOGIN_DEVICE: 'org:login:device',
ORG_LOGIN_WEB: 'org:login:web'
Expand Down
12 changes: 7 additions & 5 deletions packages/salesforcedx-vscode-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
forceLightningLwcCreate,
forceLightningLwcTestCreate,
forceOpenDocumentation,
forceOrgCreate,
orgCreate,
forceOrgDelete,
forcePackageInstall,
forceProjectWithManifestCreate,
Expand Down Expand Up @@ -113,6 +113,7 @@ import { showTelemetryMessage, telemetryService } from './telemetry';
import {
isCLIInstalled,
setNodeExtraCaCerts,
setSfLogLevel,
setUpOrgExpirationWatcher
} from './util';
import { OrgAuthInfo } from './util/authInfo';
Expand Down Expand Up @@ -152,9 +153,9 @@ function registerCommands(
'sfdx.force.open.documentation',
forceOpenDocumentation
);
const forceOrgCreateCmd = vscode.commands.registerCommand(
'sfdx.force.org.create',
forceOrgCreate
const orgCreateCmd = vscode.commands.registerCommand(
'sfdx.org.create',
orgCreate
);
const orgOpenCmd = vscode.commands.registerCommand(ORG_OPEN_COMMAND, orgOpen);
const deleteSourceCmd = vscode.commands.registerCommand(
Expand Down Expand Up @@ -390,7 +391,7 @@ function registerCommands(
dataQuerySelectionCmd,
forceDiffFile,
forceOpenDocumentationCmd,
forceOrgCreateCmd,
orgCreateCmd,
forceOrgDeleteDefaultCmd,
forceOrgDeleteUsernameCmd,
forceRefreshSObjectsCmd,
Expand Down Expand Up @@ -543,6 +544,7 @@ export async function activate(extensionContext: vscode.ExtensionContext) {
// process.cwd().
ensureCurrentWorkingDirIsProjectPath(rootWorkspacePath);
setNodeExtraCaCerts();
setSfLogLevel();
await telemetryService.initializeService(extensionContext);
showTelemetryMessage(extensionContext);

Expand Down
4 changes: 2 additions & 2 deletions packages/salesforcedx-vscode-core/src/messages/i18n.ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export const messages = {
parameter_gatherer_invalid_forceide_url:
'forceide:// 形式の URL が無効です。登録者の組織から、設定の Apex デバッガのページに表示される forceide:// 形式の URL をコピー・ペーストしてください。',

force_org_create_default_scratch_org_text:
org_create_default_scratch_org_text:
'SFDX: デフォルトのスクラッチ組織を作成...',
force_org_create_result_parsing_error:
org_create_result_parsing_error:
'組織を作成するレスポンスの処理中に予期せぬエラーが発生しました。',

org_open_default_scratch_org_text: 'SFDX: デフォルトの組織を開く',
Expand Down
5 changes: 2 additions & 3 deletions packages/salesforcedx-vscode-core/src/messages/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ export const messages = {
parameter_gatherer_placeholder_delete_default_org:
'Confirm to continue deleting the default org',

force_org_create_default_scratch_org_text:
'SFDX: Create a Default Scratch Org...',
force_org_create_result_parsing_error:
org_create_default_scratch_org_text: 'SFDX: Create a Default Scratch Org...',
org_create_result_parsing_error:
'An unexpected error occurred while processing the org create response.',

org_open_default_scratch_org_text: 'SFDX: Open Default Org',
Expand Down
7 changes: 3 additions & 4 deletions packages/salesforcedx-vscode-core/src/orgPicker/orgList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class OrgList implements vscode.Disposable {
let quickPickList = [
'$(plus) ' + nls.localize('org_login_web_authorize_org_text'),
'$(plus) ' + nls.localize('org_login_web_authorize_dev_hub_text'),
'$(plus) ' + nls.localize('force_org_create_default_scratch_org_text'),
'$(plus) ' + nls.localize('org_create_default_scratch_org_text'),
'$(plus) ' + nls.localize('force_auth_access_token_authorize_org_text'),
'$(plus) ' + nls.localize('org_list_clean_text')
];
Expand All @@ -147,9 +147,8 @@ export class OrgList implements vscode.Disposable {
vscode.commands.executeCommand('sfdx.org.login.web.dev.hub');
return { type: 'CONTINUE', data: {} };
}
case '$(plus) ' +
nls.localize('force_org_create_default_scratch_org_text'): {
vscode.commands.executeCommand('sfdx.force.org.create');
case '$(plus) ' + nls.localize('org_create_default_scratch_org_text'): {
vscode.commands.executeCommand('sfdx.org.create');
return { type: 'CONTINUE', data: {} };
}
case '$(plus) ' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ENABLE_SOURCE_TRACKING_FOR_DEPLOY_RETRIEVE,
INTERNAL_DEVELOPMENT_FLAG,
ENV_NODE_EXTRA_CA_CERTS,
ENV_SF_LOG_LEVEL,
PREFER_DEPLOY_ON_SAVE_ENABLED,
PUSH_OR_DEPLOY_ON_SAVE_ENABLED,
PUSH_OR_DEPLOY_ON_SAVE_OVERRIDE_CONFLICTS,
Expand Down Expand Up @@ -105,6 +106,13 @@ export class SfdxCoreSettings {
);
}

public getSfLogLevel(): string {
return this.getConfigValue(
ENV_SF_LOG_LEVEL,
process.env.SF_LOG_LEVEL ?? ''
);
}

private getConfigValue<T>(key: string, defaultValue: T): T {
return this.getConfiguration().get<T>(key, defaultValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { window } from 'vscode';
import {
ENV_NODE_EXTRA_CA_CERTS,
ENV_SF_DISABLE_TELEMETRY,
ENV_SF_LOG_LEVEL,
SFDX_CLI_DOWNLOAD_LINK
} from '../constants';
import { nls } from '../messages';
Expand Down Expand Up @@ -58,3 +59,10 @@ export function setNodeExtraCaCerts() {
sfdxCoreSettings.getNodeExtraCaCerts()
);
}

export function setSfLogLevel() {
GlobalCliEnvironment.environmentVariables.set(
ENV_SF_LOG_LEVEL,
sfdxCoreSettings.getSfLogLevel()
);
}
1 change: 1 addition & 0 deletions packages/salesforcedx-vscode-core/src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {
isCLIInstalled,
isCLITelemetryAllowed,
setNodeExtraCaCerts,
setSfLogLevel,
showCLINotInstalledMessage
} from './cliConfiguration';
export { workspaceUtils } from './rootWorkspace';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { expect } from 'chai';
import * as path from 'path';
import * as sinon from 'sinon';
import * as vscode from 'vscode';
import { AliasGatherer, ForceOrgCreateExecutor } from '../../../src/commands';
import { AliasGatherer, OrgCreateExecutor } from '../../../src/commands';
import { nls } from '../../../src/messages';
import { workspaceUtils } from '../../../src/util';

Expand Down Expand Up @@ -125,17 +125,17 @@ describe('Force Org Create', () => {
const CONFIG_FILE = 'configFile.txt';
const TEST_ALIAS = 'testAlias';
const TEST_ORG_EXPIRATION_DAYS = '7';
const forceOrgCreateBuilder = new ForceOrgCreateExecutor();
const forceOrgCreateBuilder = new OrgCreateExecutor();
const createCommand = forceOrgCreateBuilder.build({
file: path.join(workspaceUtils.getRootWorkspacePath(), CONFIG_FILE),
alias: TEST_ALIAS,
expirationDays: TEST_ORG_EXPIRATION_DAYS
});
expect(createCommand.toCommand()).to.equal(
`sfdx force:org:create -f ${CONFIG_FILE} --setalias ${TEST_ALIAS} --durationdays ${TEST_ORG_EXPIRATION_DAYS} --setdefaultusername --json --loglevel fatal`
`sfdx org:create:scratch --definition-file ${CONFIG_FILE} --alias ${TEST_ALIAS} --duration-days ${TEST_ORG_EXPIRATION_DAYS} --set-default --json`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command uses JSON, which is why I'm asking about .withJson(false) in the other command.

);
expect(createCommand.description).to.equal(
nls.localize('force_org_create_default_scratch_org_text')
nls.localize('org_create_default_scratch_org_text')
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,16 +340,14 @@ describe('orgList Tests', () => {
);
});

it('should return Continue and call force:org:create command if SFDX: Create a Default Scratch Org is selected', async () => {
it('should return Continue and call org:create:scratch command if SFDX: Create a Default Scratch Org is selected', async () => {
orgListStub.returns(orgsList);
quickPickStub.returns(
'$(plus) ' + nls.localize('force_org_create_default_scratch_org_text')
'$(plus) ' + nls.localize('org_create_default_scratch_org_text')
);
const response = await orgList.setDefaultOrg();
expect(response.type).to.equal('CONTINUE');
expect(executeCommandStub.calledWith('sfdx.force.org.create')).to.equal(
true
);
expect(executeCommandStub.calledWith('sfdx.org.create')).to.equal(true);
});

it('should return Continue and call force:auth:dev:hub command if SFDX: Authorize a Dev Hub is selected', async () => {
Expand Down
Loading