start of implementing direct client access

This commit is contained in:
Nate Jones 2015-03-08 15:28:01 -07:00
parent ced348b87c
commit 7aace0ee2a

View file

@ -1,6 +1,8 @@
package main package main
import ( import (
"github.com/fsouza/go-dockerclient"
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
@ -29,17 +31,54 @@ var imagesCommand ImagesCommand
func (x *ImagesCommand) Execute(args []string) error { func (x *ImagesCommand) Execute(args []string) error {
var images *[]Image
stat, err := os.Stdin.Stat()
if err != nil {
return fmt.Errorf("error reading stdin stat", err)
}
if (stat.Mode() & os.ModeCharDevice) == 0 {
// read in stdin // read in stdin
stdin, err := ioutil.ReadAll(os.Stdin) stdin, err := ioutil.ReadAll(os.Stdin)
if err != nil { if err != nil {
return fmt.Errorf("error reading all input", err) return fmt.Errorf("error reading all input", err)
} }
images, err := parseImagesJSON(stdin) images, err = parseImagesJSON(stdin)
if err != nil { if err != nil {
return err 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 { if imagesCommand.Dot {
fmt.Printf(jsonToDot(images)) fmt.Printf(jsonToDot(images))
} else if imagesCommand.Tree { } else if imagesCommand.Tree {