Skip to content

Commit

Permalink
Show fluffy decorations only when we can or when the user wants it
Browse files Browse the repository at this point in the history
Show the bullets or fluffy decoration when the user doesn't specify
-C/--no-colour or that we have some proper terminal (i.e: not running under the
unit tests/CI)

Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel authored and tekton-robot committed Jan 15, 2020
1 parent 137eb1d commit 4ae08d7
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 218 deletions.
24 changes: 12 additions & 12 deletions pkg/cmd/pipeline/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,53 +30,53 @@ import (
cliopts "k8s.io/cli-runtime/pkg/genericclioptions"
)

const describeTemplate = `{{color "bold" "Name"}}: {{ .PipelineName }}
const describeTemplate = `{{decorate "bold" "Name"}}: {{ .PipelineName }}
{{color "underline bold" "Resources\n"}}
{{decorate "underline bold" "Resources\n"}}
{{- $rl := len .Pipeline.Spec.Resources }}{{ if eq $rl 0 }}
No resources
{{- else }}
NAME TYPE
{{- range $i, $r := .Pipeline.Spec.Resources }}
∙ {{$r.Name }} {{ $r.Type }}
{{decorate "bullet" $r.Name }} {{ $r.Type }}
{{- end }}
{{- end }}
{{color "underline bold" "Params\n"}}
{{decorate "underline bold" "Params\n"}}
{{- $l := len .Pipeline.Spec.Params }}{{ if eq $l 0 }}
No params
{{- else }}
NAME TYPE DEFAULT VALUE
{{- range $i, $p := .Pipeline.Spec.Params }}
{{- if not $p.Default }}
∙ {{ $p.Name }} {{ $p.Type }} {{ "" }}
{{decorate "bullet" $p.Name }} {{ $p.Type }} {{ "" }}
{{- else }}
{{- if eq $p.Type "string" }}
∙ {{ $p.Name }} {{ $p.Type }} {{ $p.Default.StringVal }}
{{decorate "bullet" $p.Name }} {{ $p.Type }} {{ $p.Default.StringVal }}
{{- else }}
∙ {{ $p.Name }} {{ $p.Type }} {{ $p.Default.ArrayVal }}
{{decorate "bullet" $p.Name }} {{ $p.Type }} {{ $p.Default.ArrayVal }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{color "underline bold" "Tasks\n"}}
{{decorate "underline bold" "Tasks\n"}}
{{- $tl := len .Pipeline.Spec.Tasks }}{{ if eq $tl 0 }}
No tasks
{{- else }}
NAME TASKREF RUNAFTER
{{- range $i, $t := .Pipeline.Spec.Tasks }}
∙ {{ $t.Name }} {{ $t.TaskRef.Name }} {{ $t.RunAfter }}
{{decorate "bullet" $t.Name }} {{ $t.TaskRef.Name }} {{ $t.RunAfter }}
{{- end }}
{{- end }}
{{color "underline bold" "PipelineRuns\n"}}
{{decorate "underline bold" "PipelineRuns\n"}}
{{- $rl := len .PipelineRuns.Items }}{{ if eq $rl 0 }}
No pipelineruns
{{- else }}
NAME STARTED DURATION STATUS
{{- range $i, $pr := .PipelineRuns.Items }}
∙ {{ $pr.Name }} {{ formatAge $pr.Status.StartTime $.Params.Time }} {{ formatDuration $pr.Status.StartTime $pr.Status.CompletionTime }} {{ formatCondition $pr.Status.Conditions }}
{{decorate "bullet" $pr.Name }} {{ formatAge $pr.Status.StartTime $.Params.Time }} {{ formatDuration $pr.Status.StartTime $pr.Status.CompletionTime }} {{ formatCondition $pr.Status.Conditions }}
{{- end }}
{{- end }}
`
Expand Down Expand Up @@ -147,7 +147,7 @@ func printPipelineDescription(out io.Writer, p cli.Params, pname string) error {
"formatAge": formatted.Age,
"formatDuration": formatted.Duration,
"formatCondition": formatted.Condition,
"color": formatted.ColorAttr,
"decorate": formatted.DecorateAttr,
}

w := tabwriter.NewWriter(out, 0, 5, 3, ' ', tabwriter.TabIndent)
Expand Down
58 changes: 29 additions & 29 deletions pkg/cmd/pipeline/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ func TestPipelinesDescribe_with_run(t *testing.T) {
"Tasks\n",
" No tasks\n",
"PipelineRuns\n",
" NAME STARTED DURATION STATUS",
" pipeline-run-1 15 minutes ago 10 minutes Succeeded\n",
" NAME STARTED DURATION STATUS",
" pipeline-run-1 15 minutes ago 10 minutes Succeeded\n",
}

text := strings.Join(expected, "\n")
Expand Down Expand Up @@ -243,11 +243,11 @@ func TestPipelinesDescribe_with_task_run(t *testing.T) {
"Params\n",
" No params\n",
"Tasks\n",
" NAME TASKREF RUNAFTER",
" task taskref [one two]\n",
" NAME TASKREF RUNAFTER",
" task taskref [one two]\n",
"PipelineRuns\n",
" NAME STARTED DURATION STATUS",
" pipeline-run-1 15 minutes ago 10 minutes Succeeded\n",
" NAME STARTED DURATION STATUS",
" pipeline-run-1 15 minutes ago 10 minutes Succeeded\n",
}

text := strings.Join(expected, "\n")
Expand Down Expand Up @@ -317,17 +317,17 @@ func TestPipelinesDescribe_with_resource_param_task_run(t *testing.T) {
expected := []string{
"Name: pipeline\n",
"Resources\n",
" NAME TYPE",
" name git\n",
" NAME TYPE",
" name git\n",
"Params\n",
" NAME TYPE DEFAULT VALUE",
" pipeline-param string somethingdifferent\n",
" NAME TYPE DEFAULT VALUE",
" pipeline-param string somethingdifferent\n",
"Tasks\n",
" NAME TASKREF RUNAFTER",
" task taskref [one two]\n",
" NAME TASKREF RUNAFTER",
" task taskref [one two]\n",
"PipelineRuns\n",
" NAME STARTED DURATION STATUS",
" pipeline-run-1 15 minutes ago 10 minutes Succeeded\n",
" NAME STARTED DURATION STATUS",
" pipeline-run-1 15 minutes ago 10 minutes Succeeded\n",
}

text := strings.Join(expected, "\n")
Expand Down Expand Up @@ -404,24 +404,24 @@ func TestPipelinesDescribe_with_multiple_resource_param_task_run(t *testing.T) {
expected := []string{
"Name: pipeline\n",
"Resources\n",
" NAME TYPE",
" code git",
" name git",
" repo git",
" artifact-image image",
" code-image image\n",
" NAME TYPE",
" code git",
" name git",
" repo git",
" artifact-image image",
" code-image image\n",
"Params\n",
" NAME TYPE DEFAULT VALUE",
" pipeline-param string somethingdifferent",
" rev-param array [booms booms booms]",
" pipeline-param2 string ",
" rev-param2 array \n",
" NAME TYPE DEFAULT VALUE",
" pipeline-param string somethingdifferent",
" rev-param array [booms booms booms]",
" pipeline-param2 string ",
" rev-param2 array \n",
"Tasks\n",
" NAME TASKREF RUNAFTER",
" task taskref [one two]\n",
" NAME TASKREF RUNAFTER",
" task taskref [one two]\n",
"PipelineRuns\n",
" NAME STARTED DURATION STATUS",
" pipeline-run-1 15 minutes ago 10 minutes Succeeded\n",
" NAME STARTED DURATION STATUS",
" pipeline-run-1 15 minutes ago 10 minutes Succeeded\n",
}

text := strings.Join(expected, "\n")
Expand Down
16 changes: 8 additions & 8 deletions pkg/cmd/pipelineresource/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ import (
cliopts "k8s.io/cli-runtime/pkg/genericclioptions"
)

const templ = `{{color "bold" "Name"}}: {{ .PipelineResource.Name }}
{{color "bold" "Namespace"}}: {{ .PipelineResource.Namespace }}
{{color "bold" "PipelineResource Type"}}: {{ .PipelineResource.Spec.Type }}
const templ = `{{decorate "bold" "Name"}}: {{ .PipelineResource.Name }}
{{decorate "bold" "Namespace"}}: {{ .PipelineResource.Namespace }}
{{decorate "bold" "PipelineResource Type"}}: {{ .PipelineResource.Spec.Type }}
{{color "underline bold" "Params\n"}}
{{decorate "underline bold" "Params\n"}}
{{- $l := len .PipelineResource.Spec.Params }}{{ if eq $l 0 }}
No params
{{- else }}
NAME VALUE
{{- range $i, $p := .PipelineResource.Spec.Params }}
∙ {{ $p.Name }} {{ $p.Value }}
{{decorate "bullet" $p.Name }} {{ $p.Value }}
{{- end }}
{{- end }}
{{color "underline bold" "Secret Params\n"}}
{{decorate "underline bold" "Secret Params\n"}}
{{- $l := len .PipelineResource.Spec.SecretParams }}{{ if eq $l 0 }}
No secret params
{{- else }}
FIELDNAME SECRETNAME
{{- range $i, $p := .PipelineResource.Spec.SecretParams }}
∙ {{ $p.FieldName }} {{ $p.SecretName }}
{{decorate "bullet" $p.FieldName }} {{ $p.SecretName }}
{{- end }}
{{- end }}
`
Expand Down Expand Up @@ -115,7 +115,7 @@ func printPipelineResourceDescription(s *cli.Stream, p cli.Params, preName strin

w := tabwriter.NewWriter(s.Out, 0, 5, 3, ' ', tabwriter.TabIndent)
FuncMap := template.FuncMap{
"color": formatted.ColorAttr,
"decorate": formatted.DecorateAttr,
}
t := template.Must(template.New("Describe PipelineResource").Funcs(FuncMap).Parse(templ))

Expand Down
14 changes: 7 additions & 7 deletions pkg/cmd/pipelineresource/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func TestPipelineResourceDescribe_WithParams(t *testing.T) {
"PipelineResource Type: image",
"",
"Params\n",
" NAME VALUE",
" URL quay.io/tekton/controller",
" NAME VALUE",
" URL quay.io/tekton/controller",
"",
"Secret Params\n",
" No secret params",
Expand Down Expand Up @@ -137,13 +137,13 @@ func TestPipelineResourceDescribe_WithSecretParams(t *testing.T) {
"PipelineResource Type: image",
"",
"Params\n",
" NAME VALUE",
" URL quay.io/tekton/controller",
" TAG latest",
" NAME VALUE",
" URL quay.io/tekton/controller",
" TAG latest",
"",
"Secret Params\n",
" FIELDNAME SECRETNAME",
" githubToken github-secrets",
" FIELDNAME SECRETNAME",
" githubToken github-secrets",
"",
}

Expand Down
30 changes: 15 additions & 15 deletions pkg/cmd/pipelinerun/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,60 +30,60 @@ import (
cliopts "k8s.io/cli-runtime/pkg/genericclioptions"
)

const templ = `{{color "bold" "Name"}}: {{ .PipelineRun.Name }}
{{color "bold" "Namespace"}}: {{ .PipelineRun.Namespace }}
const templ = `{{decorate "bold" "Name"}}: {{ .PipelineRun.Name }}
{{decorate "bold" "Namespace"}}: {{ .PipelineRun.Namespace }}
{{- $pRefName := pipelineRefExists .PipelineRun.Spec }}{{- if ne $pRefName "" }}
{{color "bold" "Pipeline Ref"}}: {{ $pRefName }}
{{decorate "bold" "Pipeline Ref"}}: {{ $pRefName }}
{{- end }}
{{- if ne .PipelineRun.Spec.ServiceAccountName "" }}
{{color "bold" "Service Account"}}: {{ .PipelineRun.Spec.ServiceAccountName }}
{{decorate "bold" "Service Account"}}: {{ .PipelineRun.Spec.ServiceAccountName }}
{{- end }}
{{color "underline bold" "Status\n"}}
{{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 "" }}
{{color "underline bold" "Message\n"}}
{{decorate "underline bold" "Message\n"}}
{{ $msg }}
{{- end }}
{{color "underline bold" "Resources\n"}}
{{decorate "underline bold" "Resources\n"}}
{{- $l := len .PipelineRun.Spec.Resources }}{{ if eq $l 0 }}
No resources
{{- else }}
NAME RESOURCE REF
{{- range $i, $r := .PipelineRun.Spec.Resources }}
{{- $rRefName := pipelineResourceRefExists $r }}{{- if ne $rRefName "" }}
∙ {{$r.Name }} {{ $r.ResourceRef.Name }}
{{decorate "bullet" $r.Name }} {{ $r.ResourceRef.Name }}
{{- else }}
∙ {{$r.Name }} {{ "" }}
{{decorate "bullet" $r.Name }} {{ "" }}
{{- end }}
{{- end }}
{{- end }}
{{color "underline bold" "Params\n"}}
{{decorate "underline bold" "Params\n"}}
{{- $l := len .PipelineRun.Spec.Params }}{{ if eq $l 0 }}
No params
{{- else }}
NAME VALUE
{{- range $i, $p := .PipelineRun.Spec.Params }}
{{- if eq $p.Value.Type "string" }}
∙ {{ $p.Name }} {{ $p.Value.StringVal }}
{{decorate "bullet" $p.Name }} {{ $p.Value.StringVal }}
{{- else }}
∙ {{ $p.Name }} {{ $p.Value.ArrayVal }}
{{decorate "bullet" $p.Name }} {{ $p.Value.ArrayVal }}
{{- end }}
{{- end }}
{{- end }}
{{color "underline bold" "Taskruns\n"}}
{{decorate "underline bold" "Taskruns\n"}}
{{- $l := len .TaskrunList }}{{ if eq $l 0 }}
No taskruns
{{- else }}
NAME TASK NAME STARTED DURATION STATUS
{{- range $taskrun := .TaskrunList }}
∙ {{ $taskrun.TaskrunName }} {{ $taskrun.PipelineTaskName }} {{ formatAge $taskrun.Status.StartTime $.Params.Time }} {{ formatDuration $taskrun.Status.StartTime $taskrun.Status.CompletionTime }} {{ formatCondition $taskrun.Status.Conditions }}
{{decorate "bullet" $taskrun.TaskrunName }} {{ $taskrun.PipelineTaskName }} {{ formatAge $taskrun.Status.StartTime $.Params.Time }} {{ formatDuration $taskrun.Status.StartTime $taskrun.Status.CompletionTime }} {{ formatCondition $taskrun.Status.Conditions }}
{{- end }}
{{- end }}
`
Expand Down Expand Up @@ -164,7 +164,7 @@ func printPipelineRunDescription(s *cli.Stream, prName string, p cli.Params) err
"hasFailed": hasFailed,
"pipelineRefExists": validate.PipelineRefExists,
"pipelineResourceRefExists": validate.PipelineResourceRefExists,
"color": formatted.ColorAttr,
"decorate": formatted.DecorateAttr,
}

w := tabwriter.NewWriter(s.Out, 0, 5, 3, ' ', tabwriter.TabIndent)
Expand Down
Loading

0 comments on commit 4ae08d7

Please sign in to comment.