github.com/vmware/govmomi@v0.51.0/cli/tags/update.go (about) 1 // © Broadcom. All Rights Reserved. 2 // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 3 // SPDX-License-Identifier: Apache-2.0 4 5 package tags 6 7 import ( 8 "context" 9 "flag" 10 11 "github.com/vmware/govmomi/cli" 12 "github.com/vmware/govmomi/cli/flags" 13 "github.com/vmware/govmomi/vapi/tags" 14 ) 15 16 type update struct { 17 *flags.ClientFlag 18 19 tag tags.Tag 20 cat string 21 } 22 23 func init() { 24 cli.Register("tags.update", &update{}) 25 } 26 27 func (cmd *update) Register(ctx context.Context, f *flag.FlagSet) { 28 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 29 cmd.ClientFlag.Register(ctx, f) 30 31 f.StringVar(&cmd.tag.Name, "n", "", "Name of tag") 32 f.StringVar(&cmd.tag.Description, "d", "", "Description of tag") 33 f.StringVar(&cmd.cat, "c", "", "Tag category") 34 } 35 36 func (cmd *update) Usage() string { 37 return "NAME" 38 } 39 40 func (cmd *update) Description() string { 41 return `Update tag. 42 43 Examples: 44 govc tags.update -d "K8s zone US-CA1" k8s-zone-us-ca1 45 govc tags.update -d "K8s zone US-CA1" -c k8s-zone us-ca1` 46 } 47 48 func (cmd *update) Run(ctx context.Context, f *flag.FlagSet) error { 49 if f.NArg() != 1 { 50 return flag.ErrHelp 51 } 52 arg := f.Arg(0) 53 54 c, err := cmd.RestClient() 55 if err != nil { 56 return err 57 } 58 59 m := tags.NewManager(c) 60 tag, err := m.GetTagForCategory(ctx, arg, cmd.cat) 61 if err != nil { 62 return err 63 } 64 tag.Patch(&cmd.tag) 65 return m.UpdateTag(ctx, tag) 66 }