Skip to content

Commit

Permalink
Merge pull request #195 from Accenture/feature/193-disable-type-selec…
Browse files Browse the repository at this point in the history
…tion-when-trying-to-retrieve-a-full-bu

removed logic of requesting user to select metadatatype for retrieve …
  • Loading branch information
anasilva105 authored Aug 21, 2024
2 parents 8d0cc61 + fd6422d commit 9c9e141
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 60 deletions.
12 changes: 2 additions & 10 deletions src/devtools/commands/DevToolsAdminCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ class DevToolsAdminCommands extends DevToolsCommands {
}
log("debug", `Init payload: ${JSON.stringify(initArgs)}`);

const commandConfigured: string | undefined = await this.configureCommandWithParameters(
config,
initArgs,
[]
);
const commandConfigured: string | undefined = await this.configureCommandWithParameters(config, initArgs);
// Checks if the command is still missing so required parameter
if (this.hasPlaceholders(commandConfigured)) {
log("debug", `Required Parameters missing from Init command: ${commandConfigured}`);
Expand All @@ -89,11 +85,7 @@ class DevToolsAdminCommands extends DevToolsCommands {
try {
log("info", `Running DevTools Admin Command: Explain Types...`);
if ("command" in config && config.command) {
const commandConfigured: string | undefined = await this.configureCommandWithParameters(
config,
args,
[]
);
const commandConfigured: string | undefined = await this.configureCommandWithParameters(config, args);
log("debug", `Explain types final command: ${commandConfigured}`);
const commandResult: string | number = await this.executeCommand(
commandConfigured,
Expand Down
31 changes: 1 addition & 30 deletions src/devtools/commands/DevToolsCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ abstract class DevToolsCommands {

async configureCommandWithParameters(
config: DevToolsCommandSetting,
args: { [key: string]: string | string[] | boolean },
mdTypes: SupportedMetadataTypes[]
args: { [key: string]: string | string[] | boolean }
): Promise<string> {
log("debug", `ConfigureCommandWithParameters: ${JSON.stringify(config)}`);
let { command } = config;
Expand All @@ -54,14 +53,6 @@ abstract class DevToolsCommands {
for (const param of config.requiredParams) {
if (param in args && args[param]) {
command = command.replace(`{{${param}}}`, args[param] as string);
} else {
// Requests user
if (param.toLowerCase() === "mdtypes" && mdTypes.length) {
const userSelecteMDTypes: string | undefined = await this.handleMetadataTypeRequest(mdTypes);
if (userSelecteMDTypes) {
command = command.replace(`{{${param}}}`, `"${userSelecteMDTypes}"`);
}
}
}
}
}
Expand All @@ -78,26 +69,6 @@ abstract class DevToolsCommands {
return command;
}

async handleMetadataTypeRequest(mdTypes: SupportedMetadataTypes[]): Promise<string | undefined> {
const mdTypeInputOptions: InputOptionsSettings[] = mdTypes.map((mdType: SupportedMetadataTypes) => ({
id: mdType.apiName,
label: mdType.name,
detail: ""
}));
const userResponse: InputOptionsSettings | InputOptionsSettings[] | undefined =
await editorInput.handleQuickPickSelection(
mdTypeInputOptions,
"Please select one or multiple metadata types...",
true
);
if (userResponse && Array.isArray(userResponse)) {
const mdTypes: string = `${userResponse.map((response: InputOptionsSettings) => response.id)}`;
log("debug", `User selected metadata types: "${mdTypes}"`);
return mdTypes;
}
return;
}

hasPlaceholders(command: string): boolean {
const pattern: RegExp = /{{.*?}}/g;
return pattern.test(command);
Expand Down
20 changes: 4 additions & 16 deletions src/devtools/commands/DevToolsStandardCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,8 @@ class DevToolsStandardCommands extends DevToolsCommands {
) {
log("info", `Running DevTools Standard Command: Retrieve...`);
if ("command" in config && config.command) {
// Gets that metadata types that are supported for retrieve
const supportedMdTypes: SupportedMetadataTypes[] = this.getSupportedMetadataTypeByAction("retrieve");

// Configures the command to replace all the parameters with the values
const commandConfigured: string | undefined = await this.configureCommandWithParameters(
config,
args,
supportedMdTypes
);
const commandConfigured: string | undefined = await this.configureCommandWithParameters(config, args);

// Checks if the command is still missing so required parameter
if (this.hasPlaceholders(commandConfigured)) {
Expand All @@ -89,6 +82,7 @@ class DevToolsStandardCommands extends DevToolsCommands {

log("debug", `Retrieve Command configured: ${commandConfigured}`);
loadingNotification();

const commandResult: string | number = await this.executeCommand(commandConfigured, path, true);
if (typeof commandResult === "number") {
handleCommandResult({ success: commandResult === 0, cancelled: false });
Expand All @@ -106,15 +100,8 @@ class DevToolsStandardCommands extends DevToolsCommands {
) {
log("info", `Running DevTools Standard Command: Deploy...`);
if ("command" in config && config.command) {
// Gets that metadata types that are supported for deploy
const supportedMdTypes: SupportedMetadataTypes[] = this.getSupportedMetadataTypeByAction("deploy");

// Configures the command to replace all the parameters with the values
const commandConfigured: string | undefined = await this.configureCommandWithParameters(
config,
args,
supportedMdTypes
);
const commandConfigured: string | undefined = await this.configureCommandWithParameters(config, args);

// Checks if the command is still missing so required parameter
if (this.hasPlaceholders(commandConfigured)) {
Expand All @@ -125,6 +112,7 @@ class DevToolsStandardCommands extends DevToolsCommands {

log("debug", `Deploy Command configured: ${commandConfigured}`);
loadingNotification();

const commandResult: string | number = await this.executeCommand(commandConfigured, path, true);
if (typeof commandResult === "number") {
handleCommandResult({ success: commandResult === 0, cancelled: false });
Expand Down
8 changes: 4 additions & 4 deletions src/devtools/commands/commands.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@
"id":"retrieve",
"title": "Retrieve",
"command": "mcdev retrieve {{bu}} {{mdtypes}} {{key}} --skipInteraction",
"requiredParams": ["bu", "mdtypes"],
"optionalParams": ["key"],
"requiredParams": ["bu"],
"optionalParams": ["key", "mdtypes"],
"description": "Retrieves metadata of a business unit.",
"isAvailable": true
},
{
"id":"deploy",
"title": "Deploy",
"command": "mcdev deploy {{bu}} {{mdtypes}} {{key}} {{fromRetrieve}} --skipInteraction",
"requiredParams": ["bu", "mdtypes"],
"optionalParams": ["key", "fromRetrieve"],
"requiredParams": ["bu"],
"optionalParams": ["key", "mdtypes", "fromRetrieve"],
"description": "Deploys local metadata to a business unit.",
"isAvailable": true
},
Expand Down

0 comments on commit 9c9e141

Please sign in to comment.