github.com/vmware/govmomi@v0.43.0/govc/host/option/ls.go (about)

     1  /*
     2  Copyright (c) 2016-2017 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 option
    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/govc/option"
    26  )
    27  
    28  type ls struct {
    29  	*option.List
    30  	*flags.HostSystemFlag
    31  }
    32  
    33  func init() {
    34  	cli.Register("host.option.ls", &ls{})
    35  }
    36  
    37  func (cmd *ls) Register(ctx context.Context, f *flag.FlagSet) {
    38  	cmd.List = &option.List{}
    39  	cmd.List.ClientFlag, ctx = flags.NewClientFlag(ctx)
    40  	cmd.List.ClientFlag.Register(ctx, f)
    41  
    42  	cmd.List.OutputFlag, ctx = flags.NewOutputFlag(ctx)
    43  	cmd.List.OutputFlag.Register(ctx, f)
    44  
    45  	cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
    46  	cmd.HostSystemFlag.Register(ctx, f)
    47  }
    48  
    49  func (cmd *ls) Process(ctx context.Context) error {
    50  	if err := cmd.List.Process(ctx); err != nil {
    51  		return err
    52  	}
    53  	if err := cmd.HostSystemFlag.Process(ctx); err != nil {
    54  		return err
    55  	}
    56  	return nil
    57  }
    58  
    59  func (cmd *ls) Description() string {
    60  	return option.ListDescription + `
    61  
    62  Examples:
    63    govc host.option.ls
    64    govc host.option.ls Config.HostAgent.
    65    govc host.option.ls Config.HostAgent.plugins.solo.enableMob`
    66  }
    67  
    68  func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
    69  	host, err := cmd.HostSystem()
    70  	if err != nil {
    71  		return err
    72  	}
    73  
    74  	m, err := host.ConfigManager().OptionManager(ctx)
    75  	if err != nil {
    76  		return err
    77  	}
    78  
    79  	return cmd.Query(ctx, f, m)
    80  }