2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2016-03-16 15:19:22 -04:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2015-12-18 08:03:41 -05:00
|
|
|
"github.com/docker/docker/api/client/formatter"
|
2015-05-05 00:18:28 -04:00
|
|
|
Cli "github.com/docker/docker/cli"
|
2015-03-24 23:57:23 -04:00
|
|
|
"github.com/docker/docker/opts"
|
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
2016-01-04 19:05:26 -05:00
|
|
|
"github.com/docker/engine-api/types"
|
|
|
|
"github.com/docker/engine-api/types/filters"
|
2015-03-24 23:57:23 -04:00
|
|
|
)
|
|
|
|
|
2015-03-25 13:34:41 -04:00
|
|
|
// CmdImages lists the images in a specified repository, or all top-level images if no repository is specified.
|
|
|
|
//
|
|
|
|
// Usage: docker images [OPTIONS] [REPOSITORY]
|
2015-03-24 23:57:23 -04:00
|
|
|
func (cli *DockerCli) CmdImages(args ...string) error {
|
2015-10-08 08:46:21 -04:00
|
|
|
cmd := Cli.Subcmd("images", []string{"[REPOSITORY[:TAG]]"}, Cli.DockerCommands["images"].Description, true)
|
2015-03-24 23:57:23 -04:00
|
|
|
quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only show numeric IDs")
|
|
|
|
all := cmd.Bool([]string{"a", "-all"}, false, "Show all images (default hides intermediate images)")
|
2015-11-09 09:37:24 -05:00
|
|
|
noTrunc := cmd.Bool([]string{"-no-trunc"}, false, "Don't truncate output")
|
2015-03-24 23:57:23 -04:00
|
|
|
showDigests := cmd.Bool([]string{"-digests"}, false, "Show digests")
|
2015-12-18 08:03:41 -05:00
|
|
|
format := cmd.String([]string{"-format"}, "", "Pretty-print images using a Go template")
|
2015-03-24 23:57:23 -04:00
|
|
|
|
|
|
|
flFilter := opts.NewListOpts(nil)
|
|
|
|
cmd.Var(&flFilter, []string{"f", "-filter"}, "Filter output based on conditions provided")
|
|
|
|
cmd.Require(flag.Max, 1)
|
2015-07-03 05:26:09 -04:00
|
|
|
|
2015-03-28 21:22:46 -04:00
|
|
|
cmd.ParseFlags(args, true)
|
2015-03-24 23:57:23 -04:00
|
|
|
|
|
|
|
// Consolidate all filter flags, and sanity check them early.
|
|
|
|
// They'll get process in the daemon/server.
|
2015-11-25 20:27:11 -05:00
|
|
|
imageFilterArgs := filters.NewArgs()
|
2015-03-24 23:57:23 -04:00
|
|
|
for _, f := range flFilter.GetAll() {
|
|
|
|
var err error
|
|
|
|
imageFilterArgs, err = filters.ParseFlag(f, imageFilterArgs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-03 15:20:36 -05:00
|
|
|
var matchName string
|
2015-04-13 10:33:52 -04:00
|
|
|
if cmd.NArg() == 1 {
|
2015-12-03 15:20:36 -05:00
|
|
|
matchName = cmd.Arg(0)
|
2015-04-13 10:33:52 -04:00
|
|
|
}
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2015-12-04 17:02:06 -05:00
|
|
|
options := types.ImageListOptions{
|
2015-12-03 15:20:36 -05:00
|
|
|
MatchName: matchName,
|
|
|
|
All: *all,
|
|
|
|
Filters: imageFilterArgs,
|
2015-04-13 10:33:52 -04:00
|
|
|
}
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2016-03-16 15:19:22 -04:00
|
|
|
images, err := cli.client.ImageList(context.Background(), options)
|
2015-12-03 15:20:36 -05:00
|
|
|
if err != nil {
|
2015-04-13 10:33:52 -04:00
|
|
|
return err
|
|
|
|
}
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2015-12-18 08:03:41 -05:00
|
|
|
f := *format
|
|
|
|
if len(f) == 0 {
|
|
|
|
if len(cli.ImagesFormat()) > 0 && !*quiet {
|
|
|
|
f = cli.ImagesFormat()
|
2015-03-24 23:57:23 -04:00
|
|
|
} else {
|
2015-12-18 08:03:41 -05:00
|
|
|
f = "table"
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|
2015-04-13 10:33:52 -04:00
|
|
|
}
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2015-12-18 08:03:41 -05:00
|
|
|
imagesCtx := formatter.ImageContext{
|
|
|
|
Context: formatter.Context{
|
|
|
|
Output: cli.out,
|
|
|
|
Format: f,
|
|
|
|
Quiet: *quiet,
|
|
|
|
Trunc: !*noTrunc,
|
|
|
|
},
|
|
|
|
Digest: *showDigests,
|
|
|
|
Images: images,
|
2015-04-13 10:33:52 -04:00
|
|
|
}
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2015-12-18 08:03:41 -05:00
|
|
|
imagesCtx.Write()
|
|
|
|
|
2015-03-24 23:57:23 -04:00
|
|
|
return nil
|
|
|
|
}
|