github.com/canthefason/helm@v2.2.1-0.20170221172616-16b043b8d505+incompatible/cmd/helm/get_hooks.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 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 const getHooksHelp = ` 29 This command downloads hooks for a given release. 30 31 Hooks are formatted in YAML and separated by the YAML '---\n' separator. 32 ` 33 34 type getHooksCmd struct { 35 release string 36 out io.Writer 37 client helm.Interface 38 version int32 39 } 40 41 func newGetHooksCmd(client helm.Interface, out io.Writer) *cobra.Command { 42 ghc := &getHooksCmd{ 43 out: out, 44 client: client, 45 } 46 cmd := &cobra.Command{ 47 Use: "hooks [flags] RELEASE_NAME", 48 Short: "download all hooks for a named release", 49 Long: getHooksHelp, 50 RunE: func(cmd *cobra.Command, args []string) error { 51 if len(args) == 0 { 52 return errReleaseRequired 53 } 54 ghc.release = args[0] 55 ghc.client = ensureHelmClient(ghc.client) 56 return ghc.run() 57 }, 58 } 59 cmd.Flags().Int32Var(&ghc.version, "revision", 0, "get the named release with revision") 60 return cmd 61 } 62 63 func (g *getHooksCmd) run() error { 64 res, err := g.client.ReleaseContent(g.release, helm.ContentReleaseVersion(g.version)) 65 if err != nil { 66 fmt.Fprintln(g.out, g.release) 67 return prettyError(err) 68 } 69 70 for _, hook := range res.Release.Hooks { 71 fmt.Fprintf(g.out, "---\n# %s\n%s", hook.Name, hook.Manifest) 72 } 73 return nil 74 }