(dockerCLI command.Cli)
| 24 | } |
| 25 | |
| 26 | func newSecretCreateCommand(dockerCLI command.Cli) *cobra.Command { |
| 27 | options := createOptions{ |
| 28 | labels: opts.NewListOpts(opts.ValidateLabel), |
| 29 | } |
| 30 | |
| 31 | cmd := &cobra.Command{ |
| 32 | Use: "create [OPTIONS] SECRET [file|-]", |
| 33 | Short: "Create a secret from a file or STDIN as content", |
| 34 | Args: cli.RequiresRangeArgs(1, 2), |
| 35 | RunE: func(cmd *cobra.Command, args []string) error { |
| 36 | options.name = args[0] |
| 37 | if len(args) == 2 { |
| 38 | options.file = args[1] |
| 39 | } |
| 40 | return runSecretCreate(cmd.Context(), dockerCLI, options) |
| 41 | }, |
| 42 | ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 43 | switch len(args) { |
| 44 | case 0: |
| 45 | // No completion for the first argument, which is the name for |
| 46 | // the new secret, but if a non-empty name is given, we return |
| 47 | // it as completion to allow "tab"-ing to the next completion. |
| 48 | return []string{toComplete}, cobra.ShellCompDirectiveNoFileComp |
| 49 | case 1: |
| 50 | // Second argument is either "-" or a file to load. |
| 51 | // |
| 52 | // TODO(thaJeztah): provide completion for "-". |
| 53 | return nil, cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveDefault |
| 54 | default: |
| 55 | // Command only accepts two arguments. |
| 56 | return nil, cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveNoFileComp |
| 57 | } |
| 58 | }, |
| 59 | DisableFlagsInUseLine: true, |
| 60 | } |
| 61 | flags := cmd.Flags() |
| 62 | flags.VarP(&options.labels, "label", "l", "Secret labels") |
| 63 | flags.StringVarP(&options.driver, "driver", "d", "", "Secret driver") |
| 64 | flags.SetAnnotation("driver", "version", []string{"1.31"}) |
| 65 | flags.StringVar(&options.templateDriver, "template-driver", "", "Template driver") |
| 66 | flags.SetAnnotation("template-driver", "version", []string{"1.37"}) |
| 67 | |
| 68 | return cmd |
| 69 | } |
| 70 | |
| 71 | func runSecretCreate(ctx context.Context, dockerCLI command.Cli, options createOptions) error { |
| 72 | apiClient := dockerCLI.Client() |
searching dependent graphs…