Skip to content

Commit 0c80652

Browse files
chore: display file name only
1 parent 4266e06 commit 0c80652

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

src/commands/agent/validate/authoring-bundle.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
import { readFileSync } from 'node:fs';
17-
import { basename, join } from 'node:path';
17+
import { join } from 'node:path';
1818
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
1919
import { Messages, SfError } from '@salesforce/core';
2020
import { MultiStageOutput } from '@oclif/multi-stage-output';
@@ -65,23 +65,17 @@ export default class AgentValidateAuthoringBundle extends SfCommand<AgentValidat
6565

6666
public async run(): Promise<AgentValidateAuthoringBundleResult> {
6767
const { flags } = await this.parse(AgentValidateAuthoringBundle);
68-
let apiName = flags['api-name'];
69-
let agentFilePath;
70-
if (apiName) {
71-
const authoringBundleDir = findAuthoringBundle(this.project!.getPath(), apiName);
72-
if (!authoringBundleDir) {
73-
throw new SfError(messages.getMessage('error.agentNotFound', [apiName]), 'AgentNotFoundError', [
74-
messages.getMessage('error.agentNotFoundAction'),
75-
]);
76-
}
77-
agentFilePath = join(authoringBundleDir, `${apiName}.agent`);
78-
} else {
79-
// Prompt user to select an .agent file from the project and extract the API name from it
80-
agentFilePath = await promptForFileByExtensions(AgentValidateAuthoringBundle.FLAGGABLE_PROMPTS['api-name'], [
81-
'.agent',
68+
// If api-name is not provided, prompt user to select an .agent file from the project and extract the API name from it
69+
const apiName =
70+
flags['api-name'] ??
71+
(await promptForFileByExtensions(AgentValidateAuthoringBundle.FLAGGABLE_PROMPTS['api-name'], ['.agent'], true));
72+
const authoringBundleDir = findAuthoringBundle(this.project!.getPath(), apiName);
73+
if (!authoringBundleDir) {
74+
throw new SfError(messages.getMessage('error.agentNotFound', [apiName]), 'AgentNotFoundError', [
75+
messages.getMessage('error.agentNotFoundAction'),
8276
]);
83-
apiName = basename(agentFilePath, '.agent');
8477
}
78+
8579
const mso = new MultiStageOutput<{ status: string; errors: string }>({
8680
jsonEnabled: this.jsonEnabled(),
8781
title: `Validating ${apiName} Authoring Bundle`,
@@ -109,7 +103,7 @@ export default class AgentValidateAuthoringBundle extends SfCommand<AgentValidat
109103
const conn = targetOrg.getConnection(flags['api-version']);
110104
// Call Agent.compileAfScript() API
111105
await sleep(Duration.seconds(2));
112-
await Agent.compileAfScript(conn, readFileSync(agentFilePath, 'utf8'));
106+
await Agent.compileAfScript(conn, readFileSync(join(authoringBundleDir, `${apiName}.agent`), 'utf8'));
113107
mso.updateData({ status: 'COMPLETED' });
114108
mso.stop('completed');
115109
return {

src/flags.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { readdir } from 'node:fs/promises';
18-
import { join, relative } from 'node:path';
18+
import { basename, join, relative } from 'node:path';
1919
import { Interfaces } from '@oclif/core';
2020
import { Flags } from '@salesforce/sf-plugins-core';
2121
import { Connection, Messages, SfError } from '@salesforce/core';
@@ -151,15 +151,23 @@ export const promptForAiEvaluationDefinitionApiName = async (
151151
});
152152
};
153153

154-
export const promptForFileByExtensions = async (flagDef: FlaggablePrompt, extensions: string[]): Promise<string> => {
154+
export const promptForFileByExtensions = async (
155+
flagDef: FlaggablePrompt,
156+
extensions: string[],
157+
fileNameOnly = false
158+
): Promise<string> => {
155159
const hiddenDirs = await getHiddenDirs();
156-
const yamlFiles = await traverseForFiles(process.cwd(), extensions, ['node_modules', ...hiddenDirs]);
160+
const files = await traverseForFiles(process.cwd(), extensions, ['node_modules', ...hiddenDirs]);
157161
return autocomplete({
158162
message: flagDef.promptMessage ?? flagDef.message.replace(/\.$/, ''),
159163
// eslint-disable-next-line @typescript-eslint/require-await
160164
source: async (input) => {
161-
const arr = yamlFiles.map((o) => ({ name: relative(process.cwd(), o), value: o }));
162-
165+
let arr;
166+
if (fileNameOnly) {
167+
arr = files.map((o) => ({ name: basename(o).split('.')[0], value: basename(o).split('.')[0] }));
168+
} else {
169+
arr = files.map((o) => ({ name: relative(process.cwd(), o), value: o }));
170+
}
163171
if (!input) return arr;
164172
return arr.filter((o) => o.name.includes(input));
165173
},

0 commit comments

Comments
 (0)