github.com/Beeketing/helm@v2.12.1+incompatible/cmd/helm/get_notes.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 main 18 19 import ( 20 "fmt" 21 "io" 22 23 "github.com/spf13/cobra" 24 25 "k8s.io/helm/pkg/helm" 26 ) 27 28 var getNotesHelp = ` 29 This command shows notes provided by the chart of a named release. 30 ` 31 32 type getNotesCmd struct { 33 release string 34 out io.Writer 35 client helm.Interface 36 version int32 37 } 38 39 func newGetNotesCmd(client helm.Interface, out io.Writer) *cobra.Command { 40 get := &getNotesCmd{ 41 out: out, 42 client: client, 43 } 44 45 cmd := &cobra.Command{ 46 Use: "notes [flags] RELEASE_NAME", 47 Short: "displays the notes of the named release", 48 Long: getNotesHelp, 49 PreRunE: func(_ *cobra.Command, _ []string) error { return setupConnection() }, 50 RunE: func(cmd *cobra.Command, args []string) error { 51 if len(args) == 0 { 52 return errReleaseRequired 53 } 54 get.release = args[0] 55 if get.client == nil { 56 get.client = newClient() 57 } 58 return get.run() 59 }, 60 } 61 62 f := cmd.Flags() 63 settings.AddFlagsTLS(f) 64 f.Int32Var(&get.version, "revision", 0, "get the notes of the named release with revision") 65 66 // set defaults from environment 67 settings.InitTLS(f) 68 69 return cmd 70 } 71 72 func (n *getNotesCmd) run() error { 73 res, err := n.client.ReleaseStatus(n.release, helm.StatusReleaseVersion(n.version)) 74 if err != nil { 75 return prettyError(err) 76 } 77 78 if len(res.Info.Status.Notes) > 0 { 79 fmt.Fprintf(n.out, "NOTES:\n%s\n", res.Info.Status.Notes) 80 } 81 return nil 82 }