MCPcopy Create free account
hub / github.com/Effect-TS/effect / file

Function file

packages/effect/src/unstable/cli/Prompt.ts:878–915  ·  view source on GitHub ↗
(options: FileOptions = {})

Source from the content-addressed store, hash-verified

876 * @since 4.0.0
877 */
878export const file = (options: FileOptions = {}): Prompt<string> => {
879 const opts: FileOptionsReq = {
880 type: options.type ?? "file",
881 message: options.message ?? `Choose a file`,
882 startingPath: Option.fromUndefinedOr(options.startingPath),
883 default: Option.fromUndefinedOr(options.default),
884 maxPerPage: options.maxPerPage ?? 10,
885 filter: options.filter ?? (() => Effect.succeed(true))
886 }
887 const initialState: Effect.Effect<
888 FileState,
889 never,
890 Environment
891 > = Effect.gen(function*() {
892 const currentPath = yield* resolveCurrentPath(Option.none(), opts)
893 const path = yield* Path.Path
894 const defaultPath = Option.map(opts.default, (defaultValue) => path.resolve(currentPath, defaultValue))
895 const initialPath = Option.match(defaultPath, {
896 onNone: () => currentPath,
897 onSome: (defaultPath) => path.dirname(defaultPath)
898 })
899 const files = yield* getFileList(initialPath, opts)
900 const cursor = Option.match(defaultPath, {
901 onNone: () => 0,
902 onSome: (defaultPath) => {
903 const index = files.indexOf(path.basename(defaultPath))
904 return index === -1 ? 0 : index
905 }
906 })
907 const confirm = Confirm.Hide()
908 return { cursor, files, allFiles: files, query: "", path: Option.map(defaultPath, path.dirname), confirm }
909 })
910 return custom(initialState, {
911 render: handleFileRender(opts),
912 process: handleFileProcess(opts),
913 clear: handleFileClear(opts)
914 })
915}
916
917/**
918 * Composes prompts by using the output of this prompt to create the next prompt.

Callers

nothing calls this directly

Calls 7

resolveCurrentPathFunction · 0.85
handleFileRenderFunction · 0.85
handleFileProcessFunction · 0.85
handleFileClearFunction · 0.85
customFunction · 0.70
succeedMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected