MCPcopy Index your code
hub / github.com/Effect-TS/effect / processSelection

Function processSelection

packages/cli/src/internal/prompt/file.ts:259–294  ·  view source on GitHub ↗
(state: State, options: FileOptions)

Source from the content-addressed store, hash-verified

257}
258
259function processSelection(state: State, options: FileOptions) {
260 return Effect.gen(function*() {
261 const fs = yield* FileSystem.FileSystem
262 const path = yield* Path.Path
263 const currentPath = yield* resolveCurrentPath(state.path, options)
264 const selectedPath = state.files[state.cursor]
265 const resolvedPath = path.resolve(currentPath, selectedPath)
266 const info = yield* Effect.orDie(fs.stat(resolvedPath))
267 if (info.type === "Directory") {
268 const files = yield* getFileList(resolvedPath, options)
269 const filesWithoutParent = files.filter((file) => file !== "..")
270 // If the user selected a directory AND the prompt type can result with
271 // a directory, we must confirm:
272 // - If the selected directory has any files
273 // - Confirm whether or not the user wants to traverse those files
274 if (options.type === "directory" || options.type === "either") {
275 return filesWithoutParent.length === 0
276 // Directory is empty so it's safe to select it
277 ? Action.Submit({ value: resolvedPath })
278 // Directory has contents - show confirmation to user
279 : Action.NextFrame({
280 state: { ...state, confirm: Confirm.Show() }
281 })
282 }
283 return Action.NextFrame({
284 state: {
285 cursor: 0,
286 files,
287 path: Option.some(resolvedPath),
288 confirm: Confirm.Hide()
289 }
290 })
291 }
292 return Action.Submit({ value: resolvedPath })
293 })
294}
295
296function handleProcess(options: FileOptions) {
297 return (input: Terminal.UserInput, state: State) =>

Callers 1

handleProcessFunction · 0.85

Calls 3

resolveCurrentPathFunction · 0.85
getFileListFunction · 0.85
statMethod · 0.80

Tested by

no test coverage detected