newHistoryCommand creates a new "docker image history" command.
(dockerCLI command.Cli)
| 26 | |
| 27 | // newHistoryCommand creates a new "docker image history" command. |
| 28 | func newHistoryCommand(dockerCLI command.Cli) *cobra.Command { |
| 29 | var opts historyOptions |
| 30 | |
| 31 | cmd := &cobra.Command{ |
| 32 | Use: "history [OPTIONS] IMAGE", |
| 33 | Short: "Show the history of an image", |
| 34 | Args: cli.ExactArgs(1), |
| 35 | RunE: func(cmd *cobra.Command, args []string) error { |
| 36 | opts.image = args[0] |
| 37 | return runHistory(cmd.Context(), dockerCLI, opts) |
| 38 | }, |
| 39 | ValidArgsFunction: completion.ImageNames(dockerCLI, 1), |
| 40 | Annotations: map[string]string{ |
| 41 | "aliases": "docker image history, docker history", |
| 42 | }, |
| 43 | DisableFlagsInUseLine: true, |
| 44 | } |
| 45 | |
| 46 | flags := cmd.Flags() |
| 47 | |
| 48 | flags.BoolVarP(&opts.human, "human", "H", true, "Print sizes and dates in human readable format") |
| 49 | flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only show image IDs") |
| 50 | flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output") |
| 51 | flags.StringVar(&opts.format, "format", "", flagsHelper.FormatHelp) |
| 52 | flags.StringVar(&opts.platform, "platform", "", `Show history for the given platform. Formatted as "os[/arch[/variant]]" (e.g., "linux/amd64")`) |
| 53 | _ = flags.SetAnnotation("platform", "version", []string{"1.48"}) |
| 54 | |
| 55 | _ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms()) |
| 56 | return cmd |
| 57 | } |
| 58 | |
| 59 | func runHistory(ctx context.Context, dockerCli command.Cli, opts historyOptions) error { |
| 60 | var options []client.ImageHistoryOption |
searching dependent graphs…