github.com/vmware/govmomi@v0.51.0/cli/vlcm/depot/offline/info.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 offline
     6  
     7  import (
     8  	"context"
     9  	"flag"
    10  	"io"
    11  
    12  	"github.com/vmware/govmomi/cli"
    13  	"github.com/vmware/govmomi/cli/flags"
    14  	"github.com/vmware/govmomi/vapi/esx/settings/depots"
    15  )
    16  
    17  type infoResult depots.SettingsDepotsOfflineContentInfo
    18  
    19  func (r infoResult) Write(w io.Writer) error {
    20  	return nil
    21  }
    22  
    23  type info struct {
    24  	*flags.ClientFlag
    25  	*flags.OutputFlag
    26  
    27  	depotId string
    28  }
    29  
    30  func init() {
    31  	cli.Register("vlcm.depot.offline.info", &info{})
    32  }
    33  
    34  func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {
    35  	cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
    36  	cmd.ClientFlag.Register(ctx, f)
    37  	cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
    38  
    39  	f.StringVar(&cmd.depotId, "depot-id", "", "The identifier of the depot. Use the 'ls' command to see the list of depots.")
    40  }
    41  
    42  func (cmd *info) Process(ctx context.Context) error {
    43  	if err := cmd.ClientFlag.Process(ctx); err != nil {
    44  		return err
    45  	}
    46  	if err := cmd.OutputFlag.Process(ctx); err != nil {
    47  		return err
    48  	}
    49  
    50  	return nil
    51  }
    52  
    53  func (cmd *info) Usage() string {
    54  	return "VLCM"
    55  }
    56  
    57  func (cmd *info) Description() string {
    58  	return `Displays the contents of an offline image depot.
    59  
    60  Examples:
    61    govc vlcm.depot.offline.info -depot-id=<your depot's identifier>`
    62  }
    63  
    64  func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
    65  	rc, err := cmd.RestClient()
    66  
    67  	if err != nil {
    68  		return err
    69  	}
    70  
    71  	dm := depots.NewManager(rc)
    72  
    73  	if d, err := dm.GetOfflineDepotContent(cmd.depotId); err != nil {
    74  		return err
    75  	} else {
    76  		if !cmd.All() {
    77  			cmd.JSON = true
    78  		}
    79  
    80  		return cmd.WriteResult(infoResult(d))
    81  	}
    82  }