github.com/thajeztah/cli@v0.0.0-20240223162942-dc6bfac81a8b/cli/command/plugin/inspect.go (about)

     1  // FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
     2  //go:build go1.19
     3  
     4  package plugin
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/docker/cli/cli"
    10  	"github.com/docker/cli/cli/command"
    11  	"github.com/docker/cli/cli/command/inspect"
    12  	flagsHelper "github.com/docker/cli/cli/flags"
    13  	"github.com/spf13/cobra"
    14  )
    15  
    16  type inspectOptions struct {
    17  	pluginNames []string
    18  	format      string
    19  }
    20  
    21  func newInspectCommand(dockerCli command.Cli) *cobra.Command {
    22  	var opts inspectOptions
    23  
    24  	cmd := &cobra.Command{
    25  		Use:   "inspect [OPTIONS] PLUGIN [PLUGIN...]",
    26  		Short: "Display detailed information on one or more plugins",
    27  		Args:  cli.RequiresMinArgs(1),
    28  		RunE: func(cmd *cobra.Command, args []string) error {
    29  			opts.pluginNames = args
    30  			return runInspect(cmd.Context(), dockerCli, opts)
    31  		},
    32  	}
    33  
    34  	flags := cmd.Flags()
    35  	flags.StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp)
    36  	return cmd
    37  }
    38  
    39  func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions) error {
    40  	client := dockerCli.Client()
    41  	getRef := func(ref string) (any, []byte, error) {
    42  		return client.PluginInspectWithRaw(ctx, ref)
    43  	}
    44  
    45  	return inspect.Inspect(dockerCli.Out(), opts.pluginNames, opts.format, getRef)
    46  }