|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | import { readdir } from 'node:fs/promises'; |
18 | | -import { join, relative } from 'node:path'; |
| 18 | +import { basename, join, relative } from 'node:path'; |
19 | 19 | import { Interfaces } from '@oclif/core'; |
20 | 20 | import { Flags } from '@salesforce/sf-plugins-core'; |
21 | 21 | import { Connection, Messages, SfError } from '@salesforce/core'; |
@@ -151,21 +151,32 @@ export const promptForAiEvaluationDefinitionApiName = async ( |
151 | 151 | }); |
152 | 152 | }; |
153 | 153 |
|
154 | | -export const promptForYamlFile = async (flagDef: FlaggablePrompt): Promise<string> => { |
| 154 | +export const promptForFileByExtensions = async ( |
| 155 | + flagDef: FlaggablePrompt, |
| 156 | + extensions: string[], |
| 157 | + fileNameOnly = false |
| 158 | +): Promise<string> => { |
155 | 159 | const hiddenDirs = await getHiddenDirs(); |
156 | | - const yamlFiles = await traverseForFiles(process.cwd(), ['.yml', '.yaml'], ['node_modules', ...hiddenDirs]); |
| 160 | + const files = await traverseForFiles(process.cwd(), extensions, ['node_modules', ...hiddenDirs]); |
157 | 161 | return autocomplete({ |
158 | | - message: flagDef.message, |
| 162 | + message: flagDef.promptMessage ?? flagDef.message.replace(/\.$/, ''), |
159 | 163 | // eslint-disable-next-line @typescript-eslint/require-await |
160 | 164 | 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 | + } |
163 | 171 | if (!input) return arr; |
164 | 172 | return arr.filter((o) => o.name.includes(input)); |
165 | 173 | }, |
166 | 174 | }); |
167 | 175 | }; |
168 | 176 |
|
| 177 | +export const promptForYamlFile = async (flagDef: FlaggablePrompt): Promise<string> => |
| 178 | + promptForFileByExtensions(flagDef, ['.yml', '.yaml']); |
| 179 | + |
169 | 180 | export const promptForFlag = async (flagDef: FlaggablePrompt): Promise<string> => { |
170 | 181 | const message = flagDef.promptMessage ?? flagDef.message.replace(/\.$/, ''); |
171 | 182 | if (flagDef.options) { |
|
0 commit comments