Skip to content

Commit

Permalink
Add emojis to pipeline/pipelinerun/task/taskrun describe
Browse files Browse the repository at this point in the history
Not showing when we don't want colours (or not a real terminal).

Add TestDecoration to test properly decorations

Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel authored and tekton-robot committed Jan 22, 2020
1 parent c0699e0 commit f430ce7
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 23 deletions.
8 changes: 4 additions & 4 deletions pkg/cmd/pipeline/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/pipelinerun/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/task/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/taskrun/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
25 changes: 22 additions & 3 deletions pkg/formatted/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 28 additions & 1 deletion pkg/formatted/color_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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())

}

0 comments on commit f430ce7

Please sign in to comment.