newSaveCommand creates a new "docker image save" command.
(dockerCLI command.Cli)
| 24 | |
| 25 | // newSaveCommand creates a new "docker image save" command. |
| 26 | func newSaveCommand(dockerCLI command.Cli) *cobra.Command { |
| 27 | var opts saveOptions |
| 28 | |
| 29 | cmd := &cobra.Command{ |
| 30 | Use: "save [OPTIONS] IMAGE [IMAGE...]", |
| 31 | Short: "Save one or more images to a tar archive (streamed to STDOUT by default)", |
| 32 | Args: cli.RequiresMinArgs(1), |
| 33 | RunE: func(cmd *cobra.Command, args []string) error { |
| 34 | opts.images = args |
| 35 | return runSave(cmd.Context(), dockerCLI, opts) |
| 36 | }, |
| 37 | Annotations: map[string]string{ |
| 38 | "aliases": "docker image save, docker save", |
| 39 | }, |
| 40 | ValidArgsFunction: completion.ImageNames(dockerCLI, -1), |
| 41 | DisableFlagsInUseLine: true, |
| 42 | } |
| 43 | |
| 44 | flags := cmd.Flags() |
| 45 | |
| 46 | flags.StringVarP(&opts.output, "output", "o", "", "Write to a file, instead of STDOUT") |
| 47 | flags.StringSliceVar(&opts.platform, "platform", []string{}, `Save only the given platform(s). Formatted as a comma-separated list of "os[/arch[/variant]]" (e.g., "linux/amd64,linux/arm64/v8")`) |
| 48 | _ = flags.SetAnnotation("platform", "version", []string{"1.48"}) |
| 49 | |
| 50 | _ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms()) |
| 51 | return cmd |
| 52 | } |
| 53 | |
| 54 | // runSave performs a save against the engine based on the specified options |
| 55 | func runSave(ctx context.Context, dockerCLI command.Cli, opts saveOptions) error { |
searching dependent graphs…