github.com/vmware/govmomi@v0.51.0/cli/host/account/account.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 account 6 7 import ( 8 "context" 9 "flag" 10 11 "github.com/vmware/govmomi/cli/flags" 12 "github.com/vmware/govmomi/object" 13 "github.com/vmware/govmomi/vim25/types" 14 ) 15 16 type AccountFlag struct { 17 *flags.ClientFlag 18 *flags.DatacenterFlag 19 *flags.HostSystemFlag 20 21 types.HostAccountSpec 22 } 23 24 func newAccountFlag(ctx context.Context) (*AccountFlag, context.Context) { 25 f := &AccountFlag{} 26 f.ClientFlag, ctx = flags.NewClientFlag(ctx) 27 f.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx) 28 f.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx) 29 return f, ctx 30 } 31 32 func (f *AccountFlag) Register(ctx context.Context, fs *flag.FlagSet) { 33 f.ClientFlag.Register(ctx, fs) 34 f.DatacenterFlag.Register(ctx, fs) 35 f.HostSystemFlag.Register(ctx, fs) 36 37 fs.StringVar(&f.Id, "id", "", "The ID of the specified account") 38 fs.StringVar(&f.Password, "password", "", "The password for the specified account id") 39 fs.StringVar(&f.Description, "description", "", "The description of the specified account") 40 } 41 42 func (f *AccountFlag) Process(ctx context.Context) error { 43 if err := f.ClientFlag.Process(ctx); err != nil { 44 return err 45 } 46 if err := f.DatacenterFlag.Process(ctx); err != nil { 47 return err 48 } 49 if err := f.HostSystemFlag.Process(ctx); err != nil { 50 return err 51 } 52 return nil 53 } 54 55 func (f *AccountFlag) HostAccountManager(ctx context.Context) (*object.HostAccountManager, error) { 56 h, err := f.HostSystem() 57 if err != nil { 58 return nil, err 59 } 60 61 return h.ConfigManager().AccountManager(ctx) 62 }