github.com/appscode/helm@v3.0.0-alpha.1+incompatible/pkg/action/printer.go (about) 1 /* 2 Copyright The Helm Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package action 18 19 import ( 20 "fmt" 21 "io" 22 "regexp" 23 "strings" 24 "text/tabwriter" 25 26 "github.com/gosuri/uitable" 27 "github.com/gosuri/uitable/util/strutil" 28 29 "helm.sh/helm/pkg/release" 30 ) 31 32 // PrintRelease prints info about a release 33 func PrintRelease(out io.Writer, rel *release.Release) { 34 if rel == nil { 35 return 36 } 37 fmt.Fprintf(out, "NAME: %s\n", rel.Name) 38 if !rel.Info.LastDeployed.IsZero() { 39 fmt.Fprintf(out, "LAST DEPLOYED: %s\n", rel.Info.LastDeployed) 40 } 41 fmt.Fprintf(out, "NAMESPACE: %s\n", rel.Namespace) 42 fmt.Fprintf(out, "STATUS: %s\n", rel.Info.Status.String()) 43 fmt.Fprintf(out, "\n") 44 if len(rel.Info.Resources) > 0 { 45 re := regexp.MustCompile(" +") 46 47 w := tabwriter.NewWriter(out, 0, 0, 2, ' ', tabwriter.TabIndent) 48 fmt.Fprintf(w, "RESOURCES:\n%s\n", re.ReplaceAllString(rel.Info.Resources, "\t")) 49 w.Flush() 50 } 51 if rel.Info.LastTestSuiteRun != nil { 52 lastRun := rel.Info.LastTestSuiteRun 53 fmt.Fprintf(out, "TEST SUITE:\n%s\n%s\n\n%s\n", 54 fmt.Sprintf("Last Started: %s", lastRun.StartedAt), 55 fmt.Sprintf("Last Completed: %s", lastRun.CompletedAt), 56 formatTestResults(lastRun.Results)) 57 } 58 59 if strings.EqualFold(rel.Info.Description, "Dry run complete") { 60 fmt.Fprintf(out, "MANIFEST:\n%s\n", rel.Manifest) 61 } 62 63 if len(rel.Info.Notes) > 0 { 64 fmt.Fprintf(out, "NOTES:\n%s\n", strings.TrimSpace(rel.Info.Notes)) 65 } 66 } 67 68 func formatTestResults(results []*release.TestRun) string { 69 tbl := uitable.New() 70 tbl.MaxColWidth = 50 71 tbl.AddRow("TEST", "STATUS", "INFO", "STARTED", "COMPLETED") 72 for i := 0; i < len(results); i++ { 73 r := results[i] 74 n := r.Name 75 s := strutil.PadRight(r.Status.String(), 10, ' ') 76 i := r.Info 77 ts := r.StartedAt 78 tc := r.CompletedAt 79 tbl.AddRow(n, s, i, ts, tc) 80 } 81 return tbl.String() 82 }