github.com/vmware/govmomi@v0.51.0/cli/host/option/ls.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 option
     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/cli/option"
    14  )
    15  
    16  type ls struct {
    17  	*option.List
    18  	*flags.HostSystemFlag
    19  }
    20  
    21  func init() {
    22  	cli.Register("host.option.ls", &ls{})
    23  }
    24  
    25  func (cmd *ls) Register(ctx context.Context, f *flag.FlagSet) {
    26  	cmd.List = &option.List{}
    27  	cmd.List.ClientFlag, ctx = flags.NewClientFlag(ctx)
    28  	cmd.List.ClientFlag.Register(ctx, f)
    29  
    30  	cmd.List.OutputFlag, ctx = flags.NewOutputFlag(ctx)
    31  	cmd.List.OutputFlag.Register(ctx, f)
    32  
    33  	cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
    34  	cmd.HostSystemFlag.Register(ctx, f)
    35  }
    36  
    37  func (cmd *ls) Process(ctx context.Context) error {
    38  	if err := cmd.List.Process(ctx); err != nil {
    39  		return err
    40  	}
    41  	if err := cmd.HostSystemFlag.Process(ctx); err != nil {
    42  		return err
    43  	}
    44  	return nil
    45  }
    46  
    47  func (cmd *ls) Description() string {
    48  	return option.ListDescription + `
    49  
    50  Examples:
    51    govc host.option.ls
    52    govc host.option.ls Config.HostAgent.
    53    govc host.option.ls Config.HostAgent.plugins.solo.enableMob`
    54  }
    55  
    56  func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
    57  	host, err := cmd.HostSystem()
    58  	if err != nil {
    59  		return err
    60  	}
    61  
    62  	m, err := host.ConfigManager().OptionManager(ctx)
    63  	if err != nil {
    64  		return err
    65  	}
    66  
    67  	return cmd.Query(ctx, f, m)
    68  }