github.com/y-taka-23/helm@v2.8.0+incompatible/cmd/helm/repo_list.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 "errors" 21 "fmt" 22 "io" 23 24 "github.com/gosuri/uitable" 25 "github.com/spf13/cobra" 26 27 "k8s.io/helm/pkg/helm/helmpath" 28 "k8s.io/helm/pkg/repo" 29 ) 30 31 type repoListCmd struct { 32 out io.Writer 33 home helmpath.Home 34 } 35 36 func newRepoListCmd(out io.Writer) *cobra.Command { 37 list := &repoListCmd{out: out} 38 39 cmd := &cobra.Command{ 40 Use: "list [flags]", 41 Short: "list chart repositories", 42 RunE: func(cmd *cobra.Command, args []string) error { 43 list.home = settings.Home 44 return list.run() 45 }, 46 } 47 48 return cmd 49 } 50 51 func (a *repoListCmd) run() error { 52 f, err := repo.LoadRepositoriesFile(a.home.RepositoryFile()) 53 if err != nil { 54 return err 55 } 56 if len(f.Repositories) == 0 { 57 return errors.New("no repositories to show") 58 } 59 table := uitable.New() 60 table.AddRow("NAME", "URL") 61 for _, re := range f.Repositories { 62 table.AddRow(re.Name, re.URL) 63 } 64 fmt.Fprintln(a.out, table) 65 return nil 66 }