Skip to content

--interactive shows a free-form text prompt (not a selection menu) when enum.ref points to a dynamic sh: variable #2958

Description

@ikshantshukla123

Description

The guide documents that enum refs can reference dynamically-computed variables:

https://taskfile.dev/docs/guide#using-variable-references-for-enum-values

version: '3'

vars:
  AVAILABLE_SERVICES:
    sh: printf 'api\nweb\ndb\n'

tasks:
  deploy:
    requires:
      vars:
        - name: SERVICE
          enum:
            ref: .AVAILABLE_SERVICES | splitLines | compact
    cmds:
      - echo "Deploying {{.SERVICE}}"

And the interactive-mode docs say "For variables with an enum, a selection menu is shown":

https://taskfile.dev/docs/guide#prompting-for-missing-variables-interactively

But when running task --interactive deploy, a free-form text prompt is shown instead of the api/web/db selection menu. Pressing enter without typing anything then fails with a confusing error:

task: Task "deploy-dynamic" cancelled because it is missing required variables:
  - SERVICE has an invalid value : '' (allowed values : [api web db])

This is a remaining gap of the fix from #2927 (which closed #2817): that fix resolves enum.ref against the fast-compiled task vars, where sh: variables are not evaluated and resolve to "". The ref then produces an empty list, so input.Prompter.Prompt falls back to Text.

The values are resolvable though: running non-interactively works and validation lists the allowed values (as shown in the error above), so the menu could be built from them.

Steps to reproduce

# Taskfile.yml
version: '3'

vars:
  AVAILABLE_SERVICES:
    sh: printf 'api\nweb\ndb\n'

tasks:
  deploy:
    requires:
      vars:
        - name: SERVICE
          enum:
            ref: .AVAILABLE_SERVICES | splitLines | compact
    cmds:
      - echo "Deploying {{.SERVICE}}"
task --interactive deploy
# Expected: selection menu with api/web/db
# Actual:   free-form text input

A static ref (ref: .ALLOWED_ENVS where ALLOWED_ENVS: [dev, staging, prod]) does show the selection menu correctly.

Impact

  • Contradicts the docs and the changelog entry for feat: support enum.ref in interactive prompts #2927 ("enum.ref now show the selection list like static enums, instead of falling back to free-form input").
  • Affects deps too, since promptDepsVars resolves their enum refs the same way.
  • The guide's own examples for dynamic enum refs are exactly the affected case.

Proposed fix

In resolveEnumRefForPrompt (requires.go), evaluate the referenced dynamic (sh:) variables before resolving the ref so the enum list is populated and a Select menu is shown.

Metadata

Metadata

Labels

area: tuiChanges related to TUI

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions