From 4595c1e32a92a1448edc4ac4895728667e5c77ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20B=C3=BCrger?= Date: Sat, 7 Dec 2024 16:16:27 +0100 Subject: [PATCH] feat: add silent for defer (#1879) Co-authored-by: Valentin Maerten --- task_test.go | 2 +- taskfile/ast/cmd.go | 5 ++++- testdata/deferred/Taskfile.yml | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/task_test.go b/task_test.go index afb40fa19d..21cfaff1cf 100644 --- a/task_test.go +++ b/task_test.go @@ -2002,8 +2002,8 @@ cmd ran task: [task-2] exit 1 task: [task-2] echo 'failing' && exit 2 failing -task: [task-2] echo 'echo ran' echo ran +task-1 ran successfully task: [task-1] echo 'task-1 ran successfully' task-1 ran successfully `) diff --git a/taskfile/ast/cmd.go b/taskfile/ast/cmd.go index 4602ea65fa..b36e05beb1 100644 --- a/taskfile/ast/cmd.go +++ b/taskfile/ast/cmd.go @@ -75,11 +75,13 @@ func (c *Cmd) UnmarshalYAML(node *yaml.Node) error { // A deferred command var deferredCmd struct { - Defer string + Defer string + Silent bool } if err := node.Decode(&deferredCmd); err == nil && deferredCmd.Defer != "" { c.Defer = true c.Cmd = deferredCmd.Defer + c.Silent = deferredCmd.Silent return nil } @@ -91,6 +93,7 @@ func (c *Cmd) UnmarshalYAML(node *yaml.Node) error { c.Defer = true c.Task = deferredCall.Defer.Task c.Vars = deferredCall.Defer.Vars + c.Silent = deferredCall.Defer.Silent return nil } diff --git a/testdata/deferred/Taskfile.yml b/testdata/deferred/Taskfile.yml index 5039288346..b193117c7d 100644 --- a/testdata/deferred/Taskfile.yml +++ b/testdata/deferred/Taskfile.yml @@ -1,12 +1,14 @@ -version: "3" +version: '3' tasks: task-1: - echo 'task-1 ran {{.PARAM}}' task-2: - - defer: { task: "task-1", vars: { PARAM: "successfully" } } + - defer: { task: 'task-1', vars: { PARAM: 'successfully' } } + - defer: { task: 'task-1', vars: { PARAM: 'successfully' }, silent: true } - defer: echo 'echo ran' + silent: true - defer: echo 'failing' && exit 2 - echo 'cmd ran' - exit 1