github.com/vmware/govmomi@v0.43.0/govc/role/remove.go (about) 1 /* 2 Copyright (c) 2016 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 role 18 19 import ( 20 "context" 21 "flag" 22 23 "github.com/vmware/govmomi/govc/cli" 24 "github.com/vmware/govmomi/govc/permissions" 25 ) 26 27 type remove struct { 28 *permissions.PermissionFlag 29 30 force bool 31 } 32 33 func init() { 34 cli.Register("role.remove", &remove{}) 35 } 36 37 func (cmd *remove) Register(ctx context.Context, f *flag.FlagSet) { 38 cmd.PermissionFlag, ctx = permissions.NewPermissionFlag(ctx) 39 cmd.PermissionFlag.Register(ctx, f) 40 41 f.BoolVar(&cmd.force, "force", false, "Force removal if role is in use") 42 } 43 44 func (cmd *remove) Process(ctx context.Context) error { 45 if err := cmd.PermissionFlag.Process(ctx); err != nil { 46 return err 47 } 48 return nil 49 } 50 51 func (cmd *remove) Usage() string { 52 return "NAME" 53 } 54 55 func (cmd *remove) Description() string { 56 return `Remove authorization role. 57 58 Examples: 59 govc role.remove MyRole 60 govc role.remove MyRole -force` 61 } 62 63 func (cmd *remove) Run(ctx context.Context, f *flag.FlagSet) error { 64 if f.NArg() != 1 { 65 return flag.ErrHelp 66 } 67 68 m, err := cmd.Manager(ctx) 69 if err != nil { 70 return err 71 } 72 73 role, err := cmd.Role(f.Arg(0)) 74 if err != nil { 75 return err 76 } 77 78 return m.RemoveRole(ctx, role.RoleId, !cmd.force) 79 }