Skip to content

Commit

Permalink
Adding template instructional message to new-app output
Browse files Browse the repository at this point in the history
  • Loading branch information
jupierce committed Jul 22, 2016
1 parent 50f1f6e commit 5c06abe
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
15 changes: 15 additions & 0 deletions pkg/generate/app/cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ import (
imageapi "github.com/openshift/origin/pkg/image/api"
)

// These constants represent common annotations keys
const (
// OpenShiftDisplayName is a common, optional annotation that stores the name displayed by a UI when referencing a resource.
OpenShiftDisplayName = "openshift.io/display-name"
)

func displayName(meta kapi.ObjectMeta) string {
// If an object has a display name, prefer it over the meta name.
displayName := meta.Annotations[OpenShiftDisplayName]
if len(displayName) > 0 {
return displayName
}
return meta.Name
}

func localOrRemoteName(meta kapi.ObjectMeta, namespace string) string {
if len(meta.Namespace) == 0 || namespace == meta.Namespace {
return meta.Name
Expand Down
34 changes: 28 additions & 6 deletions pkg/generate/app/cmd/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,32 @@ func TransformTemplate(tpl *templateapi.Template, client client.TemplateConfigsN

// DescribeGeneratedTemplate writes a description of the provided template to out.
func DescribeGeneratedTemplate(out io.Writer, input string, result *templateapi.Template, baseNamespace string) {
name := localOrRemoteName(result.ObjectMeta, baseNamespace)
if len(input) > 0 {
fmt.Fprintf(out, "--> Deploying template %s for %q\n", name, input)
qualifiedName := localOrRemoteName(result.ObjectMeta, baseNamespace)
if len(input) > 0 && result.ObjectMeta.Name != input {
fmt.Fprintf(out, "--> Deploying template %s for %q\n", qualifiedName, input)
} else {
fmt.Fprintf(out, "--> Deploying template %s\n", name)
fmt.Fprintf(out, "--> Deploying template %s\n", qualifiedName)
}
fmt.Fprintln(out)

name := displayName(result.ObjectMeta)
message := result.Message
description := result.Annotations["description"]

// If there is a message or description
if len(message) > 0 || len(description) > 0 {
fmt.Fprintf(out, " %s\n", name)
fmt.Fprintf(out, " ---------\n")
if len(description) > 0 {
fmt.Fprintf(out, " %s\n", description)
fmt.Fprintln(out)
}
if len(message) > 0 {
fmt.Fprintf(out, " %s\n", message)
fmt.Fprintln(out)
}
}

if warnings := result.Annotations[app.GenerationWarningAnnotation]; len(warnings) > 0 {
delete(result.Annotations, app.GenerationWarningAnnotation)
fmt.Fprintln(out)
Expand All @@ -63,8 +83,9 @@ func DescribeGeneratedTemplate(out io.Writer, input string, result *templateapi.
}
fmt.Fprintln(out)
}

if len(result.Parameters) > 0 {
fmt.Fprintf(out, " With parameters:\n")
fmt.Fprintf(out, " * With parameters:\n")
for _, p := range result.Parameters {
name := p.DisplayName
if len(name) == 0 {
Expand All @@ -74,7 +95,8 @@ func DescribeGeneratedTemplate(out io.Writer, input string, result *templateapi.
if len(p.Generate) > 0 {
generated = " # generated"
}
fmt.Fprintf(out, " %s=%s%s\n", name, p.Value, generated)
fmt.Fprintf(out, " * %s=%s%s\n", name, p.Value, generated)
}
fmt.Fprintln(out)
}
}
6 changes: 6 additions & 0 deletions pkg/template/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,9 @@ type Parameter struct {
// Optional: Indicates the parameter must have a value. Defaults to false.
Required bool
}

// These constants represent annotations keys affixed to templates
const (
// TemplateDisplayName is an optional annotation that stores the name displayed by a UI when referencing a template.
TemplateDisplayName = "openshift.io/display-name"
)
1 change: 1 addition & 0 deletions test/templates/testdata/guestbook.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"name": "guestbook-example",
"creationTimestamp": null,
"annotations": {
"openshift.io/display-name": "Guestbook Example",
"description": "Example shows how to build a simple multi-tier application using Kubernetes and Docker"
}
},
Expand Down
1 change: 1 addition & 0 deletions test/templates/testdata/guestbook_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"name": "guestbook-example",
"creationTimestamp": null,
"annotations": {
"openshift.io/display-name": "Guestbook Example",
"description": "Example shows how to build a simple multi-tier application using Kubernetes and Docker"
}
},
Expand Down

0 comments on commit 5c06abe

Please sign in to comment.