github.com/vmware/govmomi@v0.51.0/cli/library/rm.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 library 6 7 import ( 8 "context" 9 "flag" 10 "fmt" 11 12 "github.com/vmware/govmomi/cli" 13 "github.com/vmware/govmomi/cli/flags" 14 "github.com/vmware/govmomi/vapi/library" 15 ) 16 17 type rm struct { 18 *flags.ClientFlag 19 force bool 20 } 21 22 func init() { 23 cli.Register("library.rm", &rm{}) 24 } 25 26 func (cmd *rm) Register(ctx context.Context, f *flag.FlagSet) { 27 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 28 cmd.ClientFlag.Register(ctx, f) 29 } 30 31 func (cmd *rm) Usage() string { 32 return "NAME" 33 } 34 35 func (cmd *rm) Description() string { 36 return `Delete library or item NAME. 37 38 Examples: 39 govc library.rm /library_name 40 govc library.rm library_id # Use library id if multiple libraries have the same name 41 govc library.rm /library_name/item_name` 42 } 43 44 func (cmd *rm) Run(ctx context.Context, f *flag.FlagSet) error { 45 c, err := cmd.RestClient() 46 if err != nil { 47 return err 48 } 49 50 m := library.NewManager(c) 51 res, err := flags.ContentLibraryResult(ctx, c, "", f.Arg(0)) 52 if err != nil { 53 return err 54 } 55 56 switch t := res.GetResult().(type) { 57 case library.Library: 58 return m.DeleteLibrary(ctx, &t) 59 case library.Item: 60 return m.DeleteLibraryItem(ctx, &t) 61 default: 62 return fmt.Errorf("%q is a %T", f.Arg(0), t) 63 } 64 }