Effect CommunityEC
Effect Community8mo ago
2 replies
Moa

Accessing Default Values in Effect CLI Prompts

Is that possible or should I flip the logic to use Options.withFallbackPrompt instead? I'm trying to:

import { Command, Options, Prompt } from '@effect/cli'
import { NodeContext, NodeRuntime } from '@effect/platform-node'
import { Effect } from 'effect'

const route = Prompt.text({
  message: 'URL route to serve catsnip from',
  default: '/catsnip',
  validate: nonEmpty,
})

const prompts = Prompt.all({ route })

const skip = Options.boolean('skip').pipe(
  Options.withDescription('Skip all prompts and use defaults')
)

const init = Command.make('init', { skip }, ({ skip }) =>
  Effect.gen(function* () {
    if (!skip) {
      yield* prompts // { route: '/catsnip' } ✅
    } else {
      // how to access default values here? ⁉️
    }
  })
)

const cli = Command.run(init, { name: 'catsnip', version: '0.0.1' })

Effect.suspend(() => cli(process.argv)).pipe(
  Effect.provide(NodeContext.layer),
  NodeRuntime.runMain
)
Was this page helpful?