How to skip warning prompts when calling another task?
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 }}'
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
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 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
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'
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.
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
Sorry for the long silence... And thank you for your explanation! I'll go ahead and close the ticket.