-
Notifications
You must be signed in to change notification settings - Fork 199
/
repo_list.go
63 lines (51 loc) · 1.27 KB
/
repo_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package repo
import (
"errors"
"fmt"
"io"
"os"
"github.com/gosuri/uitable"
"github.com/spf13/cobra"
"k8s.io/helm/pkg/helm/helmpath"
"k8s.io/helm/pkg/repo"
"github.com/flant/werf/cmd/werf/helm/common"
)
type repoListCmd struct {
out io.Writer
home helmpath.Home
}
func newRepoListCmd() *cobra.Command {
var commonCmdData common.HelmCmdData
list := &repoListCmd{out: os.Stdout}
cmd := &cobra.Command{
Use: "list",
Short: "List chart repositories",
DisableFlagsInUseLine: true,
RunE: func(cmd *cobra.Command, args []string) error {
common.InitHelmSettings(&commonCmdData)
list.home = common.HelmSettings.Home
return list.run()
},
}
common.SetupHelmHome(&commonCmdData, cmd)
return cmd
}
func (a *repoListCmd) run() error {
f, err := repo.LoadRepositoriesFile(a.home.RepositoryFile())
if err != nil {
if common.IsCouldNotLoadRepositoriesFileError(err) {
return fmt.Errorf(common.CouldNotLoadRepositoriesFileErrorFormat, a.home.RepositoryFile())
}
return err
}
if len(f.Repositories) == 0 {
return errors.New("no repositories to show")
}
table := uitable.New()
table.AddRow("NAME", "URL")
for _, re := range f.Repositories {
table.AddRow(re.Name, re.URL)
}
fmt.Fprintln(a.out, table)
return nil
}