github.com/vmware/govmomi@v0.37.1/govc/tags/update.go (about) 1 /* 2 Copyright (c) 2018 VMware, Inc. 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 tags 18 19 import ( 20 "context" 21 "flag" 22 23 "github.com/vmware/govmomi/govc/cli" 24 "github.com/vmware/govmomi/govc/flags" 25 "github.com/vmware/govmomi/vapi/tags" 26 ) 27 28 type update struct { 29 *flags.ClientFlag 30 31 tag tags.Tag 32 cat string 33 } 34 35 func init() { 36 cli.Register("tags.update", &update{}) 37 } 38 39 func (cmd *update) Register(ctx context.Context, f *flag.FlagSet) { 40 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 41 cmd.ClientFlag.Register(ctx, f) 42 43 f.StringVar(&cmd.tag.Name, "n", "", "Name of tag") 44 f.StringVar(&cmd.tag.Description, "d", "", "Description of tag") 45 f.StringVar(&cmd.cat, "c", "", "Tag category") 46 } 47 48 func (cmd *update) Usage() string { 49 return "NAME" 50 } 51 52 func (cmd *update) Description() string { 53 return `Update tag. 54 55 Examples: 56 govc tags.update -d "K8s zone US-CA1" k8s-zone-us-ca1 57 govc tags.update -d "K8s zone US-CA1" -c k8s-zone us-ca1` 58 } 59 60 func (cmd *update) Run(ctx context.Context, f *flag.FlagSet) error { 61 if f.NArg() != 1 { 62 return flag.ErrHelp 63 } 64 arg := f.Arg(0) 65 66 c, err := cmd.RestClient() 67 if err != nil { 68 return err 69 } 70 71 m := tags.NewManager(c) 72 tag, err := m.GetTagForCategory(ctx, arg, cmd.cat) 73 if err != nil { 74 return err 75 } 76 tag.Patch(&cmd.tag) 77 return m.UpdateTag(ctx, tag) 78 }