Implement support for multiple args for repo remove

I found that I sometimes I want to remove multiple repos at once.
Thought I would give it a Go to try and to make that a bit easier to do.

This is my first contribution to the Helm code base, and I am doing this
party to become more familiar with Helm and Go. So please point me in
the right direction if I've missed to change something.

Usually, I'd create an issue before creating a PR. If this change is
unwanted, please feel free to discard it – no hard feelings. I made it
mostly as an exercise anyway, so it was not wasted time for me.

Signed-off-by: Andreas Lindhé <andreas@lindhe.io>
pull/7791/head
Andreas Lindhé 6 years ago
parent e0856a56cc
commit 2fa5f1d498

@ -32,7 +32,7 @@ import (
) )
type repoRemoveOptions struct { type repoRemoveOptions struct {
name string names []string
repoFile string repoFile string
repoCache string repoCache string
} }
@ -41,14 +41,14 @@ func newRepoRemoveCmd(out io.Writer) *cobra.Command {
o := &repoRemoveOptions{} o := &repoRemoveOptions{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "remove [NAME]", Use: "remove [REPO1 [REPO2 ...]]",
Aliases: []string{"rm"}, Aliases: []string{"rm"},
Short: "remove a chart repository", Short: "remove a chart repository",
Args: require.ExactArgs(1), Args: require.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
o.repoFile = settings.RepositoryConfig o.repoFile = settings.RepositoryConfig
o.repoCache = settings.RepositoryCache o.repoCache = settings.RepositoryCache
o.name = args[0] o.names = args
return o.run(out) return o.run(out)
}, },
} }
@ -70,18 +70,20 @@ func (o *repoRemoveOptions) run(out io.Writer) error {
return errors.New("no repositories configured") return errors.New("no repositories configured")
} }
if !r.Remove(o.name) { for _, name := range o.names {
return errors.Errorf("no repo named %q found", o.name) if !r.Remove(name) {
} return errors.Errorf("no repo named %q found", name)
if err := r.WriteFile(o.repoFile, 0644); err != nil { }
return err if err := r.WriteFile(o.repoFile, 0644); err != nil {
} return err
}
if err := removeRepoCache(o.repoCache, o.name); err != nil { if err := removeRepoCache(o.repoCache, name); err != nil {
return err return err
}
fmt.Fprintf(out, "%q has been removed from your repositories\n", name)
} }
fmt.Fprintf(out, "%q has been removed from your repositories\n", o.name)
return nil return nil
} }

Loading…
Cancel
Save