github.com/stefanmcshane/helm@v0.0.0-20221213002717-88a4a2c6e77d/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  	"log"
    23  
    24  	"github.com/spf13/cobra"
    25  
    26  	"github.com/stefanmcshane/helm/cmd/helm/require"
    27  	"github.com/stefanmcshane/helm/pkg/action"
    28  )
    29  
    30  var getNotesHelp = `
    31  This command shows notes provided by the chart of a named release.
    32  `
    33  
    34  func newGetNotesCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
    35  	client := action.NewGet(cfg)
    36  
    37  	cmd := &cobra.Command{
    38  		Use:   "notes RELEASE_NAME",
    39  		Short: "download the notes for a named release",
    40  		Long:  getNotesHelp,
    41  		Args:  require.ExactArgs(1),
    42  		ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
    43  			if len(args) != 0 {
    44  				return nil, cobra.ShellCompDirectiveNoFileComp
    45  			}
    46  			return compListReleases(toComplete, args, cfg)
    47  		},
    48  		RunE: func(cmd *cobra.Command, args []string) error {
    49  			res, err := client.Run(args[0])
    50  			if err != nil {
    51  				return err
    52  			}
    53  			if len(res.Info.Notes) > 0 {
    54  				fmt.Fprintf(out, "NOTES:\n%s\n", res.Info.Notes)
    55  			}
    56  			return nil
    57  		},
    58  	}
    59  
    60  	f := cmd.Flags()
    61  	f.IntVar(&client.Version, "revision", 0, "get the named release with revision")
    62  	err := cmd.RegisterFlagCompletionFunc("revision", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
    63  		if len(args) == 1 {
    64  			return compListRevisions(toComplete, cfg, args[0])
    65  		}
    66  		return nil, cobra.ShellCompDirectiveNoFileComp
    67  	})
    68  
    69  	if err != nil {
    70  		log.Fatal(err)
    71  	}
    72  
    73  	return cmd
    74  }