github.com/vmware/govmomi@v0.51.0/cli/cluster/rule/remove.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 rule
     6  
     7  import (
     8  	"context"
     9  	"flag"
    10  
    11  	"github.com/vmware/govmomi/cli"
    12  	"github.com/vmware/govmomi/vim25/types"
    13  )
    14  
    15  type remove struct {
    16  	*InfoFlag
    17  }
    18  
    19  func init() {
    20  	cli.Register("cluster.rule.remove", &remove{})
    21  }
    22  
    23  func (cmd *remove) Register(ctx context.Context, f *flag.FlagSet) {
    24  	cmd.InfoFlag, ctx = NewInfoFlag(ctx)
    25  	cmd.InfoFlag.Register(ctx, f)
    26  }
    27  
    28  func (cmd *remove) Process(ctx context.Context) error {
    29  	if cmd.name == "" {
    30  		return flag.ErrHelp
    31  	}
    32  	return cmd.InfoFlag.Process(ctx)
    33  }
    34  
    35  func (cmd *remove) Description() string {
    36  	return `Remove cluster rule.
    37  
    38  Examples:
    39    govc cluster.group.remove -cluster my_cluster -name my_rule`
    40  }
    41  
    42  func (cmd *remove) Run(ctx context.Context, f *flag.FlagSet) error {
    43  	rule, err := cmd.Rule(ctx)
    44  	if err != nil {
    45  		return err
    46  	}
    47  
    48  	update := types.ArrayUpdateSpec{
    49  		Operation: types.ArrayUpdateOperationRemove,
    50  		RemoveKey: rule.info.GetClusterRuleInfo().Key,
    51  	}
    52  
    53  	return cmd.Apply(ctx, update, nil)
    54  }