task icon indicating copy to clipboard operation
task copied to clipboard

How to skip warning prompts when calling another task?

Open thetillhoff opened this issue 8 months ago • 3 comments

Description

In the docs, it's stated that a prompt can be skipped with --yes. Is this also possible when calling another task with task: taskname? If yes, how?

Version

3.43.3

Operating system

macOS

Experiments Enabled

No response

Example Taskfile

# https://taskfile.dev

version: '3'

tasks:
  foo:
    cmds:
      - for:
          var: CLI_ARGS
        task: bar
        vars:
          CLI_ARGS: '{{ .ITEM }}'

  bar:
    internal: true
    prompt: Are you sure?
    cmds:
      - echo 'Hello world'
    vars:
      CLI_ARGS: '{{ .CLI_ARGS }}'

thetillhoff avatar May 29 '25 19:05 thetillhoff

Hello ! You can skip all prompts with --yes (-y), but you cannot skip only a specific prompt when calling another task.

In our example you can do this :

task foo -y -- args
Are you sure? [assuming yes]
task: [bar] echo 'Hello world'
Hello world

vmaerten avatar May 31 '25 12:05 vmaerten

Hi & thanks for the response. What you described is also the workaround I came up with.

It's working, but not perfectly.

My use case can be described as similar to deleting files in a loop. One task is "delete-file" and the other "delete-files". Both listen to cli-args. "delete-file" only accepts a single arg and "delete-files" multiple args. "delete-files" then loops over its args and calls "delete-file" for each of them.

Both tasks ask for confirmation once (per call).

If "delete-files" is supplied with --yes, I'd like it to pass the --yes also to tasks it calls. This doesn't seem to be supported (yet).

It feels it should be achievable with not too much effort. If it's something you're open to adding, and agree that it might be a good first issue, I'd invest some time into it.

thetillhoff avatar Jun 02 '25 23:06 thetillhoff

@thetillhoff in your specific case, setting a task var might workout better (in the short term). A CLI Special Variable CLI_YES would seem like a reasonable addition IMHO.

version: '3'

tasks:
  foo:
    cmds:
      - for:
          var: CLI_ARGS
        task: bar
        vars:
          CLI_ARGS: '{{ .ITEM }}'

  bar:
    internal: true
    cmds:
      - echo 'rm {{if .YES}} -i {{end}} fubar'
    vars:
      CLI_ARGS: '{{ .CLI_ARGS }}'

Call with $ task foo YES=1 -- foo

trulede avatar Jun 12 '25 10:06 trulede

I found that if you make the prompt an empty string, it will skip the prompt. For example:

version: '3'

tasks:
  foo:
    cmds:
      - task: bar
        vars:
          NOPROMPT: true

  bar:
    internal: true
    prompt: '{{if not .NOPROMPT}}Are you sure?{{end}}'
    cmds:
      - echo 'Hello world'

CafeLungo avatar Jul 21 '25 15:07 CafeLungo

Thank you for your responses! If I understood your proposal correctly, @trudele, then it wouldn't allow to have a prompt on the "wrapper" foo, but skip the prompt for the bar calls. So it's similar to the original workaround with -y.

@CafeLungo , nice finding &idea! But, similar answer as above, I'd like both tasks to be callable by themselves.

thetillhoff avatar Jul 22 '25 18:07 thetillhoff

If "delete-files" is supplied with --yes, I'd like it to pass the --yes also to tasks it calls. This doesn't seem to be supported (yet).

@thetillhoff as @vmaerten explains, this is how it currently works. So I think your case is covered. This example needs a bit of work for variable handling (around ITEM) ... otherwise it demonstrates the behaviors.

version: '3'

vars:
  GREETING: Hello, World!

tasks:
  delete-file:
    prompt: Delete file?
    vars:
      ITEM: "{{ .ITEM }} defalt {{ .CLI_ARGS }}"
    cmds:
      - echo "delete file {{ .CLI_ARGS }}"

  delete-files:
    prompt: Delete files?
    cmds:
      - for:
          var: CLI_ARGS
        task: delete-file
        vars:
          ITEM: '{{ .ITEM }}'
$ task -y delete-file -- foo
Delete file? [assuming yes]
task: [delete-file] echo "delete file foo"
delete file foo

$ task -y delete-files -- foo bar
Delete files? [assuming yes]
Delete file? [assuming yes]
task: [delete-file] echo "delete file foo bar"
delete file foo bar
Delete file? [assuming yes]
task: [delete-file] echo "delete file foo bar"
delete file foo bar

trulede avatar Jul 27 '25 13:07 trulede

Sorry for the long silence... And thank you for your explanation! I'll go ahead and close the ticket.

thetillhoff avatar Sep 03 '25 21:09 thetillhoff