|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 | import { readFileSync } from 'node:fs'; |
17 | | -import { basename, join } from 'node:path'; |
| 17 | +import { join } from 'node:path'; |
18 | 18 | import { SfCommand, Flags } from '@salesforce/sf-plugins-core'; |
19 | 19 | import { Messages, SfError } from '@salesforce/core'; |
20 | 20 | import { MultiStageOutput } from '@oclif/multi-stage-output'; |
@@ -65,23 +65,17 @@ export default class AgentValidateAuthoringBundle extends SfCommand<AgentValidat |
65 | 65 |
|
66 | 66 | public async run(): Promise<AgentValidateAuthoringBundleResult> { |
67 | 67 | 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'), |
82 | 76 | ]); |
83 | | - apiName = basename(agentFilePath, '.agent'); |
84 | 77 | } |
| 78 | + |
85 | 79 | const mso = new MultiStageOutput<{ status: string; errors: string }>({ |
86 | 80 | jsonEnabled: this.jsonEnabled(), |
87 | 81 | title: `Validating ${apiName} Authoring Bundle`, |
@@ -109,7 +103,7 @@ export default class AgentValidateAuthoringBundle extends SfCommand<AgentValidat |
109 | 103 | const conn = targetOrg.getConnection(flags['api-version']); |
110 | 104 | // Call Agent.compileAfScript() API |
111 | 105 | await sleep(Duration.seconds(2)); |
112 | | - await Agent.compileAfScript(conn, readFileSync(agentFilePath, 'utf8')); |
| 106 | + await Agent.compileAfScript(conn, readFileSync(join(authoringBundleDir, `${apiName}.agent`), 'utf8')); |
113 | 107 | mso.updateData({ status: 'COMPLETED' }); |
114 | 108 | mso.stop('completed'); |
115 | 109 | return { |
|
0 commit comments