From 7aace0ee2a504988c867e45e431c3400ae92907e Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Sun, 8 Mar 2015 15:28:01 -0700 Subject: [PATCH] start of implementing direct client access --- images.go | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/images.go b/images.go index 05773d0..53235e8 100644 --- a/images.go +++ b/images.go @@ -1,6 +1,8 @@ package main import ( + "github.com/fsouza/go-dockerclient" + "bytes" "encoding/json" "fmt" @@ -29,15 +31,52 @@ var imagesCommand ImagesCommand func (x *ImagesCommand) Execute(args []string) error { - // read in stdin - stdin, err := ioutil.ReadAll(os.Stdin) + var images *[]Image + + stat, err := os.Stdin.Stat() if err != nil { - return fmt.Errorf("error reading all input", err) + return fmt.Errorf("error reading stdin stat", err) } - images, err := parseImagesJSON(stdin) - if err != nil { - return err + if (stat.Mode() & os.ModeCharDevice) == 0 { + // read in stdin + stdin, err := ioutil.ReadAll(os.Stdin) + if err != nil { + return fmt.Errorf("error reading all input", err) + } + + images, err = parseImagesJSON(stdin) + if err != nil { + return err + } + + } else { + + // grab directly from docker daemon + client, err := docker.NewClient("unix:///var/run/docker.sock") + if err != nil { + return err + } + + clientImages, err := client.ListImages(docker.ListImagesOptions{All: true}) + if err != nil { + return err + } + + var ims []Image + for _, image := range clientImages { + // fmt.Println(image) + ims = append(ims, Image{ + image.ID, + image.ParentID, + image.RepoTags, + image.VirtualSize, + image.Size, + image.Created, + }) + } + + images = &ims } if imagesCommand.Dot {