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

Loading…
Cancel
Save