diff --git a/pkg/cmd/pipeline/describe.go b/pkg/cmd/pipeline/describe.go index 574e543f2..65412db4f 100644 --- a/pkg/cmd/pipeline/describe.go +++ b/pkg/cmd/pipeline/describe.go @@ -34,7 +34,7 @@ import ( const describeTemplate = `{{decorate "bold" "Name"}}: {{ .PipelineName }} {{decorate "bold" "Namespace"}}: {{ .Pipeline.Namespace }} -{{decorate "underline bold" "Resources\n"}} +{{decorate "resources" ""}}{{decorate "underline bold" "Resources\n"}} {{- $rl := len .Pipeline.Spec.Resources }}{{ if eq $rl 0 }} No resources {{- else }} @@ -44,7 +44,7 @@ const describeTemplate = `{{decorate "bold" "Name"}}: {{ .PipelineName }} {{- end }} {{- end }} -{{decorate "underline bold" "Params\n"}} +{{decorate "params" ""}}{{decorate "underline bold" "Params\n"}} {{- $l := len .Pipeline.Spec.Params }}{{ if eq $l 0 }} No params {{- else }} @@ -62,7 +62,7 @@ const describeTemplate = `{{decorate "bold" "Name"}}: {{ .PipelineName }} {{- end }} {{- end }} -{{decorate "underline bold" "Tasks\n"}} +{{decorate "tasks" ""}}{{decorate "underline bold" "Tasks\n"}} {{- $tl := len .Pipeline.Spec.Tasks }}{{ if eq $tl 0 }} No tasks {{- else }} @@ -72,7 +72,7 @@ const describeTemplate = `{{decorate "bold" "Name"}}: {{ .PipelineName }} {{- end }} {{- end }} -{{decorate "underline bold" "PipelineRuns\n"}} +{{decorate "pipelineruns" ""}}{{decorate "underline bold" "PipelineRuns\n"}} {{- $rl := len .PipelineRuns.Items }}{{ if eq $rl 0 }} No pipelineruns {{- else }} diff --git a/pkg/cmd/pipelinerun/describe.go b/pkg/cmd/pipelinerun/describe.go index 847fd87d7..49f161f98 100644 --- a/pkg/cmd/pipelinerun/describe.go +++ b/pkg/cmd/pipelinerun/describe.go @@ -39,17 +39,17 @@ const templ = `{{decorate "bold" "Name"}}: {{ .PipelineRun.Name }} {{decorate "bold" "Service Account"}}: {{ .PipelineRun.Spec.ServiceAccountName }} {{- end }} -{{decorate "underline bold" "Status\n"}} +{{decorate "status" ""}}{{decorate "underline bold" "Status\n"}} STARTED DURATION STATUS {{ formatAge .PipelineRun.Status.StartTime .Params.Time }} {{ formatDuration .PipelineRun.Status.StartTime .PipelineRun.Status.CompletionTime }} {{ formatCondition .PipelineRun.Status.Conditions }} {{- $msg := hasFailed .PipelineRun -}} {{- if ne $msg "" }} -{{decorate "underline bold" "Message\n"}} +{{decorate "message" ""}}{{decorate "underline bold" "Message\n"}} {{ $msg }} {{- end }} -{{decorate "underline bold" "Resources\n"}} +{{decorate "resources" ""}}{{decorate "underline bold" "Resources\n"}} {{- $l := len .PipelineRun.Spec.Resources }}{{ if eq $l 0 }} No resources {{- else }} @@ -63,7 +63,7 @@ STARTED DURATION STATUS {{- end }} {{- end }} -{{decorate "underline bold" "Params\n"}} +{{decorate "params" ""}}{{decorate "underline bold" "Params\n"}} {{- $l := len .PipelineRun.Spec.Params }}{{ if eq $l 0 }} No params {{- else }} @@ -77,7 +77,7 @@ STARTED DURATION STATUS {{- end }} {{- end }} -{{decorate "underline bold" "Taskruns\n"}} +{{decorate "taskruns" ""}}{{decorate "underline bold" "Taskruns\n"}} {{- $l := len .TaskrunList }}{{ if eq $l 0 }} No taskruns {{- else }} diff --git a/pkg/cmd/task/describe.go b/pkg/cmd/task/describe.go index 4d340c3af..cf176b75b 100644 --- a/pkg/cmd/task/describe.go +++ b/pkg/cmd/task/describe.go @@ -33,7 +33,7 @@ import ( const describeTemplate = `{{decorate "bold" "Name"}}: {{ .Task.Name }} {{decorate "bold" "Namespace"}}: {{ .Task.Namespace }} -{{decorate "underline bold" "Input Resources\n"}} +{{decorate "inputresources" ""}}{{decorate "underline bold" "Input Resources\n"}} {{- if not .Task.Spec.Inputs }} No input resources @@ -48,7 +48,7 @@ const describeTemplate = `{{decorate "bold" "Name"}}: {{ .Task.Name }} {{- end }} {{- end }} -{{decorate "underline bold" "Output Resources\n"}} +{{decorate "outputresources" ""}}{{decorate "underline bold" "Output Resources\n"}} {{- if not .Task.Spec.Outputs }} No output resources @@ -64,7 +64,7 @@ const describeTemplate = `{{decorate "bold" "Name"}}: {{ .Task.Name }} {{- end }} {{- end }} -{{decorate "underline bold" "Params\n"}} +{{decorate "params" ""}}{{decorate "underline bold" "Params\n"}} {{- if not .Task.Spec.Inputs }} No params @@ -87,7 +87,7 @@ No params {{- end }} {{- end }} -{{decorate "underline bold" "Steps\n"}} +{{decorate "steps" ""}}{{decorate "underline bold" "Steps\n"}} {{- if eq (len .Task.Spec.Steps) 0 }} No steps @@ -97,7 +97,7 @@ No params {{- end }} {{- end }} -{{decorate "underline bold" "Taskruns\n"}} +{{decorate "taskruns" ""}}{{decorate "underline bold" "Taskruns\n"}} {{- if eq (len .TaskRuns.Items) 0 }} No taskruns diff --git a/pkg/cmd/taskrun/describe.go b/pkg/cmd/taskrun/describe.go index 562a4b169..eff93af86 100644 --- a/pkg/cmd/taskrun/describe.go +++ b/pkg/cmd/taskrun/describe.go @@ -38,7 +38,7 @@ const templ = `{{decorate "bold" "Name"}}: {{ .TaskRun.Name }} {{decorate "bold" "Service Account"}}: {{ .TaskRun.Spec.ServiceAccountName }} {{- end }} -{{decorate "underline bold" "Status"}} +{{decorate "status" ""}}{{decorate "underline bold" "Status"}} STARTED DURATION STATUS {{ formatAge .TaskRun.Status.StartTime .Params.Time }} {{ formatDuration .TaskRun.Status.StartTime .TaskRun.Status.CompletionTime }} {{ formatCondition .TaskRun.Status.Conditions }} @@ -50,7 +50,7 @@ STARTED DURATION STATUS {{ $msg }} {{- end }} -{{decorate "underline bold" "Input Resources\n"}} +{{decorate "inputresources" ""}}{{decorate "underline bold" "Input Resources\n"}} {{- $l := len .TaskRun.Spec.Inputs.Resources }}{{ if eq $l 0 }} No resources @@ -65,7 +65,7 @@ No resources {{- end }} {{- end }} -{{decorate "underline bold" "Output Resources\n"}} +{{decorate "outputresources" ""}}{{decorate "underline bold" "Output Resources\n"}} {{- $l := len .TaskRun.Spec.Outputs.Resources }}{{ if eq $l 0 }} No resources @@ -80,7 +80,7 @@ No resources {{- end }} {{- end }} -{{decorate "underline bold" "Params\n"}} +{{decorate "params" ""}}{{decorate "underline bold" "Params\n"}} {{- $l := len .TaskRun.Spec.Inputs.Params }}{{ if eq $l 0 }} No params @@ -95,7 +95,7 @@ No params {{- end }} {{- end }} -{{decorate "underline bold" "Steps\n"}} +{{decorate "steps" ""}}{{decorate "underline bold" "Steps\n"}} {{- $l := len .TaskRun.Status.Steps }}{{ if eq $l 0 }} No steps diff --git a/pkg/formatted/color.go b/pkg/formatted/color.go index afb969777..b5a7acd53 100644 --- a/pkg/formatted/color.go +++ b/pkg/formatted/color.go @@ -41,10 +41,29 @@ func DecorateAttr(attrString, message string) string { return message } - // May rewrite it as switch if we have more attributes, like "dancing - // penguins" or "drunk singer" - if attrString == "bullet" { + switch attrString { + case "bullet": return fmt.Sprintf("βˆ™ %s", message) + case "resources": + return fmt.Sprintf("πŸ“¦ ") + case "params": + return fmt.Sprintf("βš“ ") + case "tasks": + return fmt.Sprintf("πŸ—’ ") + case "pipelineruns": + return fmt.Sprintf("β›© ") + case "status": + return fmt.Sprintf("🌑️ ") + case "inputresources": + return fmt.Sprintf("πŸ“¨ ") + case "outputresources": + return fmt.Sprintf("πŸ“‘ ") + case "steps": + return fmt.Sprintf("🦢🏻 ") + case "message": + return fmt.Sprintf("πŸ’Œ ") + case "taskruns": + return fmt.Sprintf("πŸ—‚ ") } attr := color.Reset diff --git a/pkg/formatted/color_test.go b/pkg/formatted/color_test.go index f8bbedddb..bfdef2a93 100644 --- a/pkg/formatted/color_test.go +++ b/pkg/formatted/color_test.go @@ -14,9 +14,14 @@ package formatted import ( + "bytes" + "html/template" + "testing" + "github.com/fatih/color" "github.com/stretchr/testify/assert" + "github.com/tektoncd/cli/pkg/test" ) func TestRainbowsColours(t *testing.T) { @@ -40,7 +45,7 @@ func TestRainbowsColours(t *testing.T) { assert.Equal(t, rb.counter.value, uint32(0)) // Looped back to 0 } -func TestDecorateAttr(t *testing.T) { +func TestNoDecoration(t *testing.T) { type args struct { colorString string message string @@ -64,3 +69,25 @@ func TestDecorateAttr(t *testing.T) { }) } } + +func TestDecoration(t *testing.T) { + // We disable emoji and other colourful stuff while testing, + // but here we want to explicitly enable it. + color.NoColor = false + defer func() { + color.NoColor = true + }() + + funcMap := template.FuncMap{ + "decorate": DecorateAttr, + } + aTemplate := `{{decorate "bullet" "Foo"}} {{decorate "resources" ""}}{{decorate "params" ""}}{{decorate "tasks" ""}}{{decorate "pipelineruns" ""}}{{decorate "status" ""}}{{decorate "inputresources" ""}}{{decorate "outputresources" ""}}{{decorate "steps" ""}}{{decorate "message" ""}}{{decorate "taskruns" ""}}{{decorate "red" "Red"}} {{decorate "underline" "Foo"}}` + processed := template.Must(template.New("Describe Pipeline").Funcs(funcMap).Parse(aTemplate)) + buf := new(bytes.Buffer) + + if err := processed.Execute(buf, nil); err != nil { + t.Error("Could not process the template.") + } + test.AssertOutput(t, "βˆ™ Foo πŸ“¦ βš“ πŸ—’ β›© 🌑️ πŸ“¨ πŸ“‘ 🦢🏻 πŸ’Œ πŸ—‚ \x1b[91mRed\x1b[0m \x1b[4mFoo\x1b[0m", buf.String()) + +}