From 03e615d92beb195016b01a1e5c24827ccdaa3708 Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Mon, 13 May 2024 12:27:57 +0200 Subject: [PATCH 1/6] fix: list-task with multiline desc --- help.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/help.go b/help.go index abcdce92ea..ae4f9d0071 100644 --- a/help.go +++ b/help.go @@ -105,7 +105,8 @@ func (e *Executor) ListTasks(o ListOptions) (bool, error) { for _, task := range tasks { e.Logger.FOutf(w, logger.Yellow, "* ") e.Logger.FOutf(w, logger.Green, task.Task) - e.Logger.FOutf(w, logger.Default, ": \t%s", task.Desc) + desc := strings.ReplaceAll(task.Desc, "\n", " ") + e.Logger.FOutf(w, logger.Default, ": \t%s", desc) if len(task.Aliases) > 0 { e.Logger.FOutf(w, logger.Cyan, "\t(aliases: %s)", strings.Join(task.Aliases, ", ")) } From f5826d9711bd2b29b6083fa960af7404d5bb3239 Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Mon, 13 May 2024 13:38:40 +0200 Subject: [PATCH 2/6] feat: display all lines aligned in a table --- help.go | 14 ++++++++++++-- testdata/desc/Taskfile.yml | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 testdata/desc/Taskfile.yml diff --git a/help.go b/help.go index ae4f9d0071..7efd86eb14 100644 --- a/help.go +++ b/help.go @@ -105,8 +105,18 @@ func (e *Executor) ListTasks(o ListOptions) (bool, error) { for _, task := range tasks { e.Logger.FOutf(w, logger.Yellow, "* ") e.Logger.FOutf(w, logger.Green, task.Task) - desc := strings.ReplaceAll(task.Desc, "\n", " ") - e.Logger.FOutf(w, logger.Default, ": \t%s", desc) + desc := strings.Split(strings.TrimSuffix(task.Desc, "\n"), "\n") + + e.Logger.FOutf(w, logger.Default, ": \t%s", desc[0]) + + for _, d := range desc[1:] { + _, _ = fmt.Fprint(w, "\n") + //We need to keep the same color as if it was a new task to keep the output consistent + // because tabwriter cannot handle color codes + e.Logger.FOutf(w, logger.Yellow, "") + e.Logger.FOutf(w, logger.Green, "") + e.Logger.FOutf(w, logger.Default, "\t%s", d) + } if len(task.Aliases) > 0 { e.Logger.FOutf(w, logger.Cyan, "\t(aliases: %s)", strings.Join(task.Aliases, ", ")) } diff --git a/testdata/desc/Taskfile.yml b/testdata/desc/Taskfile.yml new file mode 100644 index 0000000000..2b5bcce583 --- /dev/null +++ b/testdata/desc/Taskfile.yml @@ -0,0 +1,17 @@ +version: 3 + + +tasks: + build: + aliases: + - b + desc: | + Multi-line escription with alias which is super long long long long long long + another line + third line long long long long long long long long + + + test: + aliases: + - t + desc: Single line description with alias From 5cf3be2df0f6901a69a8bc5b566c8b8ef5fda178 Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Mon, 13 May 2024 14:38:05 +0200 Subject: [PATCH 3/6] fix: display experiments --- help.go | 2 +- internal/experiments/experiments.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/help.go b/help.go index 7efd86eb14..ade010e35f 100644 --- a/help.go +++ b/help.go @@ -111,7 +111,7 @@ func (e *Executor) ListTasks(o ListOptions) (bool, error) { for _, d := range desc[1:] { _, _ = fmt.Fprint(w, "\n") - //We need to keep the same color as if it was a new task to keep the output consistent + // We need to keep the same color as if it was a new task to keep the output consistent // because tabwriter cannot handle color codes e.Logger.FOutf(w, logger.Yellow, "") e.Logger.FOutf(w, logger.Green, "") diff --git a/internal/experiments/experiments.go b/internal/experiments/experiments.go index 160f4219f2..fc859b1518 100644 --- a/internal/experiments/experiments.go +++ b/internal/experiments/experiments.go @@ -96,7 +96,8 @@ func readDotEnv() { func printExperiment(w io.Writer, l *logger.Logger, x Experiment) { l.FOutf(w, logger.Yellow, "* ") l.FOutf(w, logger.Green, x.Name) - l.FOutf(w, logger.Default, ": \t%s\n", x.String()) + l.FOutf(w, logger.Default, ": \t%s", x.String()) + fmt.Fprintf(w, "\n") } func List(l *logger.Logger) error { From 159ab0f69d3eb3fd21ec5bbaaab6cc583f93792b Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Mon, 13 May 2024 15:16:57 +0200 Subject: [PATCH 4/6] use ladicle/tabwrite to handle color --- go.mod | 3 ++- go.sum | 18 +++--------------- help.go | 16 +++------------- internal/experiments/experiments.go | 5 ++--- 4 files changed, 10 insertions(+), 32 deletions(-) diff --git a/go.mod b/go.mod index 7f84e28379..e98ac8f40a 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/go-task/task/v3 go 1.21.0 require ( + github.com/Ladicle/tabwriter v1.0.0 github.com/Masterminds/semver/v3 v3.2.1 github.com/alecthomas/chroma/v2 v2.14.0 github.com/davecgh/go-spew v1.1.1 @@ -27,7 +28,7 @@ require ( require ( github.com/dlclark/regexp2 v1.11.0 // indirect - github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect diff --git a/go.sum b/go.sum index 51df60e2aa..a67705ca6a 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,9 @@ +github.com/Ladicle/tabwriter v1.0.0 h1:DZQqPvMumBDwVNElso13afjYLNp0Z7pHqHnu0r4t9Dg= +github.com/Ladicle/tabwriter v1.0.0/go.mod h1:c4MdCjxQyTbGuQO/gvqJ+IA/89UEwrsD6hUCW98dyp4= github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= -github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU= -github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/assert/v2 v2.7.0 h1:QtqSACNS3tF7oasA8CU6A6sXZSBDqnm7RfpLl9bZqbE= -github.com/alecthomas/chroma/v2 v2.13.0 h1:VP72+99Fb2zEcYM0MeaWJmV+xQvz5v5cxRHd+ooU1lI= -github.com/alecthomas/chroma/v2 v2.13.0/go.mod h1:BUGjjsD+ndS6eX37YgTchSEG+Jg9Jv1GiZs9sqPqztk= +github.com/alecthomas/assert/v2 v2.7.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/chroma/v2 v2.14.0 h1:R3+wzpnUArGcQz7fCETQBzO5n9IMNi13iIs46aU4V9E= github.com/alecthomas/chroma/v2 v2.14.0/go.mod h1:QolEbTfmUHIMVpBqxeDnNBj2uoeI4EbYP4i6n68SG4I= github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc= @@ -17,16 +16,12 @@ github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxK github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/dominikbraun/graph v0.23.0 h1:TdZB4pPqCLFxYhdyMFb1TBdFxp8XLcJfTTBQucVPgCo= github.com/dominikbraun/graph v0.23.0/go.mod h1:yOjYyogZLY1LSG9E33JWZJiq5k83Qy2C6POAuiViluc= -github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= -github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= -github.com/go-task/template v0.0.0-20240422130016-8f6b279b1e90 h1:JBbiZ2CXIZ9Upe3O2yI5+3ksWoa7hNVNi4BINs8TIrs= -github.com/go-task/template v0.0.0-20240422130016-8f6b279b1e90/go.mod h1:RgwRaZK+kni/hJJ7/AaOE2lPQFPbAdji/DyhC6pxo4k= github.com/go-task/template v0.0.0-20240602015157-960e6f576656 h1:knZZ4zVdTBQnevBz0zSES++4Mr7wr+cHopLvHabIgkA= github.com/go-task/template v0.0.0-20240602015157-960e6f576656/go.mod h1:RgwRaZK+kni/hJJ7/AaOE2lPQFPbAdji/DyhC6pxo4k= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= @@ -37,8 +32,6 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= -github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -77,14 +70,9 @@ github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaD golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= -golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/help.go b/help.go index ade010e35f..e36cc392e3 100644 --- a/help.go +++ b/help.go @@ -7,8 +7,8 @@ import ( "io" "os" "strings" - "text/tabwriter" + "github.com/Ladicle/tabwriter" "golang.org/x/sync/errgroup" "github.com/go-task/task/v3/internal/editors" @@ -105,18 +105,8 @@ func (e *Executor) ListTasks(o ListOptions) (bool, error) { for _, task := range tasks { e.Logger.FOutf(w, logger.Yellow, "* ") e.Logger.FOutf(w, logger.Green, task.Task) - desc := strings.Split(strings.TrimSuffix(task.Desc, "\n"), "\n") - - e.Logger.FOutf(w, logger.Default, ": \t%s", desc[0]) - - for _, d := range desc[1:] { - _, _ = fmt.Fprint(w, "\n") - // We need to keep the same color as if it was a new task to keep the output consistent - // because tabwriter cannot handle color codes - e.Logger.FOutf(w, logger.Yellow, "") - e.Logger.FOutf(w, logger.Green, "") - e.Logger.FOutf(w, logger.Default, "\t%s", d) - } + desc := strings.ReplaceAll(strings.TrimSuffix(task.Desc, "\n"), "\n", "\n\t") + e.Logger.FOutf(w, logger.Default, ": \t%s", desc) if len(task.Aliases) > 0 { e.Logger.FOutf(w, logger.Cyan, "\t(aliases: %s)", strings.Join(task.Aliases, ", ")) } diff --git a/internal/experiments/experiments.go b/internal/experiments/experiments.go index fc859b1518..b7e57ee232 100644 --- a/internal/experiments/experiments.go +++ b/internal/experiments/experiments.go @@ -7,8 +7,8 @@ import ( "path/filepath" "slices" "strings" - "text/tabwriter" + "github.com/Ladicle/tabwriter" "github.com/joho/godotenv" "github.com/spf13/pflag" @@ -96,8 +96,7 @@ func readDotEnv() { func printExperiment(w io.Writer, l *logger.Logger, x Experiment) { l.FOutf(w, logger.Yellow, "* ") l.FOutf(w, logger.Green, x.Name) - l.FOutf(w, logger.Default, ": \t%s", x.String()) - fmt.Fprintf(w, "\n") + l.FOutf(w, logger.Default, ": \t%s\n", x.String()) } func List(l *logger.Logger) error { From 48bd962e246a1f95ff120a4302036fa0cd48844e Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Thu, 16 May 2024 14:52:34 -0400 Subject: [PATCH 5/6] delete empty lines Co-authored-by: Andrey Nering --- testdata/desc/Taskfile.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/testdata/desc/Taskfile.yml b/testdata/desc/Taskfile.yml index 2b5bcce583..6a5481b86d 100644 --- a/testdata/desc/Taskfile.yml +++ b/testdata/desc/Taskfile.yml @@ -1,6 +1,4 @@ version: 3 - - tasks: build: aliases: @@ -9,8 +7,6 @@ tasks: Multi-line escription with alias which is super long long long long long long another line third line long long long long long long long long - - test: aliases: - t From 2dfe192b82ec87a6069ecb5f7fe3d89742119a2a Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Fri, 28 Jun 2024 18:43:18 +0200 Subject: [PATCH 6/6] remove all /n and replace by space --- help.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/help.go b/help.go index e36cc392e3..f1bb339dad 100644 --- a/help.go +++ b/help.go @@ -105,7 +105,7 @@ func (e *Executor) ListTasks(o ListOptions) (bool, error) { for _, task := range tasks { e.Logger.FOutf(w, logger.Yellow, "* ") e.Logger.FOutf(w, logger.Green, task.Task) - desc := strings.ReplaceAll(strings.TrimSuffix(task.Desc, "\n"), "\n", "\n\t") + desc := strings.ReplaceAll(task.Desc, "\n", " ") e.Logger.FOutf(w, logger.Default, ": \t%s", desc) if len(task.Aliases) > 0 { e.Logger.FOutf(w, logger.Cyan, "\t(aliases: %s)", strings.Join(task.Aliases, ", "))