// Print prints the images to standard output. func (i Images) Print(mode utils.OutputMode) error { if len(i) == 0 { return errors.New("no images found") } switch mode { case utils.JSON: out, err := i.outputJSON() if err != nil { return err } fmt.Println(out) return nil case utils.Simplified: green := color.New(color.FgGreen).SprintfFunc() output := ansicolor.NewAnsiColorWriter(os.Stdout) w := utils.NewImagesTabWriter(output) defer w.Flush() for region, images := range i { if len(images) == 0 { continue } fmt.Fprintln(w, green("AWS Region: %s (%d images):", region, len(images))) fmt.Fprintln(w, " Name\tID\tState\tTags") for ix, image := range images { tags := make([]string, len(image.Tags)) for i, tag := range image.Tags { tags[i] = *tag.Key + ":" + *tag.Value } name := "" if image.Name != nil { name = *image.Name } state := *image.State if *image.State == "failed" { state += " (" + *image.StateReason.Message + ")" } fmt.Fprintf(w, "[%d] %s\t%s\t%s\t%+v\n", ix+1, name, *image.ImageId, state, tags) } fmt.Fprintln(w, "") } return nil default: return fmt.Errorf("output mode '%s' is not valid", mode) } }
// Print prints the stored images to standard output. func (i Images) Print(mode utils.OutputMode) error { if len(i.Items) == 0 { return errors.New("no images found") } switch mode { case utils.JSON: out, err := i.outputJSON() if err != nil { return err } fmt.Println(out) return nil case utils.Simplified: green := color.New(color.FgGreen).SprintfFunc() output := ansicolor.NewAnsiColorWriter(os.Stdout) w := utils.NewImagesTabWriter(output) defer w.Flush() imageDesc := "image" if len(i.Items) > 1 { imageDesc = "images" } fmt.Fprintln(w, green("GCE (%d %s):", len(i.Items), imageDesc)) fmt.Fprintln(w, " Name\tID\tStatus\tType\tDeprecated\tCreation Timestamp") for ix, image := range i.Items { deprecatedState := "" if image.Deprecated != nil { deprecatedState = image.Deprecated.State } fmt.Fprintf(w, "[%d] %s (%s)\t%d\t%s\t%s (%d)\t%s\t%s\n", ix+1, image.Name, image.Description, image.Id, image.Status, image.SourceType, image.DiskSizeGb, deprecatedState, image.CreationTimestamp, ) } return nil default: return fmt.Errorf("output mode '%s' is not valid", mode) } }
// Print prints the stored images to standard output. func (i Images) Print(mode utils.OutputMode) error { if len(i) == 0 { return errors.New("no images found") } switch mode { case utils.JSON: out, err := i.outputJSON() if err != nil { return err } fmt.Println(out) return nil case utils.Simplified: green := color.New(color.FgGreen).SprintfFunc() output := ansicolor.NewAnsiColorWriter(os.Stdout) w := utils.NewImagesTabWriter(output) defer w.Flush() imageDesc := "image" if len(i) > 1 { imageDesc = "images" } fmt.Fprintln(w, green("DO (%d %s):", len(i), imageDesc)) fmt.Fprintln(w, " Name\tID\tDistribution\tType\tRegions") for ix, image := range i { regions := make([]string, len(image.Regions)) for i, region := range image.Regions { regions[i] = region } fmt.Fprintf(w, "[%d] %s\t%d\t%s\t%s (%d)\t%+v\n", ix+1, image.Name, image.ID, image.Distribution, image.Type, image.MinDiskSize, regions) } return nil default: return fmt.Errorf("output mode '%s' is not valid", mode) } }
// Print prints the images to standard output. func (img Images) Print(mode utils.OutputMode) error { if len(img) == 0 { return errors.New("no images found (use -all flag)") } switch mode { case utils.JSON: p, err := json.MarshalIndent(img, "", " ") if err != nil { return err } fmt.Println(string(p)) return nil case utils.Simplified: green := color.New(color.FgGreen).SprintfFunc() w := utils.NewImagesTabWriter(ansicolor.NewAnsiColorWriter(os.Stdout)) defer w.Flush() fmt.Fprintln(w, green("Softlayer (%d images):", len(img))) fmt.Fprintln(w, " Name\tID\tGlobalID\tCreated\tDatacenters\tTags") for i, image := range img { created := "-" if !image.CreateDate.IsZero() { created = image.CreateDate.Format(time.RFC3339) } fmt.Fprintf(w, "[%d] %s\t%d\t%s\t%s\t%s\t%s\n", i, image.Name, image.ID, image.globalID(), created, image.datacenters(), image.tags()) } fmt.Fprintln(w) return nil default: return fmt.Errorf("output mode %q is not valid", mode) } return nil }