github.1git.de/docker/cli@v26.1.3+incompatible/cli/command/secret/cmd.go (about)

     1  package secret
     2  
     3  import (
     4  	"github.com/docker/cli/cli"
     5  	"github.com/docker/cli/cli/command"
     6  	"github.com/docker/cli/cli/command/completion"
     7  	"github.com/docker/docker/api/types"
     8  	"github.com/spf13/cobra"
     9  )
    10  
    11  // NewSecretCommand returns a cobra command for `secret` subcommands
    12  func NewSecretCommand(dockerCli command.Cli) *cobra.Command {
    13  	cmd := &cobra.Command{
    14  		Use:   "secret",
    15  		Short: "Manage Swarm secrets",
    16  		Args:  cli.NoArgs,
    17  		RunE:  command.ShowHelp(dockerCli.Err()),
    18  		Annotations: map[string]string{
    19  			"version": "1.25",
    20  			"swarm":   "manager",
    21  		},
    22  	}
    23  	cmd.AddCommand(
    24  		newSecretListCommand(dockerCli),
    25  		newSecretCreateCommand(dockerCli),
    26  		newSecretInspectCommand(dockerCli),
    27  		newSecretRemoveCommand(dockerCli),
    28  	)
    29  	return cmd
    30  }
    31  
    32  // completeNames offers completion for swarm secrets
    33  func completeNames(dockerCli command.Cli) completion.ValidArgsFn {
    34  	return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
    35  		list, err := dockerCli.Client().SecretList(cmd.Context(), types.SecretListOptions{})
    36  		if err != nil {
    37  			return nil, cobra.ShellCompDirectiveError
    38  		}
    39  		var names []string
    40  		for _, secret := range list {
    41  			names = append(names, secret.ID)
    42  		}
    43  		return names, cobra.ShellCompDirectiveNoFileComp
    44  	}
    45  }