Skip to content

Support CLI options with optional values in @effect/cli #6182

Closed as not planned

Description

@schickling-assistant

Problem

@effect/cli currently has a hard split between boolean flags and value-accepting options:

  • Options.boolean — never consumes a value (--watch)
  • Options.text / Options.choice — always require a value (--watch=mode)

There's no way to define an option that works as both a standalone flag and a value-accepting option. This is a common CLI pattern — e.g. --color vs --color=always in GNU tools, --watch vs --watch=mode in various dev tools.

Desired behavior

A flag like --watch that:

  • When absent → Option.none
  • When bare (--watch) → defaults to a specified value (e.g. 'first-failure')
  • When explicit (--watch=until-done) → uses the provided value

Possible API

const watch = Options.choice('watch', ['first-failure', 'until-done']).pipe(
  Options.withOptionalValue('first-failure'), // bare --watch → 'first-failure'
  Options.optional, // absent → Option.none
)

Or alternatively:

const watch = Options.boolean('watch').pipe(
  Options.withOptionalValue(Options.choice(['first-failure', 'until-done']), 'first-failure'),
)

Prior art

  • GNU coreutils: --color[=WHEN]
  • TypeScript compiler: --watch
  • Vitest / Jest: --watch vs --watch=mode
  • Python argparse: nargs='?' with const for the bare-flag default

Filed on behalf of @schickling

Activity

  1. schickling-assistant commented on Apr 16, 2026

    @schickling-assistant
    ContributorAuthor

    Also filed for effect-smol: #6365

    Filed on behalf of @schickling

  2. schickling-assistant commented on Apr 16, 2026

    @schickling-assistant
    ContributorAuthor

    Cross-referencing the effect-smol/v4 counterpart: Effect-TS/effect-smol#2042

    Filed on behalf of @schickling

  3. added
    3.0
    on Jul 14, 2026
  4. added
    enhancement
    on Jul 28, 2026
  5. tim-smart commented on Jul 28, 2026

    @tim-smart
    Contributor

    Automated message: Effect v3 is now under a feature freeze and is now only considering bug fixes.

    If this issue is still relevant for v4, then feel free to reopen :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.0enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions