github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/cmd/plugins/juju-metadata/listformatter.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package main
     5  
     6  import (
     7  	"fmt"
     8  	"io"
     9  	"strings"
    10  
    11  	"github.com/juju/errors"
    12  	"github.com/juju/juju/cmd/output"
    13  )
    14  
    15  func formatMetadataListTabular(writer io.Writer, value interface{}) error {
    16  	metadata, ok := value.([]MetadataInfo)
    17  	if !ok {
    18  		return errors.Errorf("expected value of type %T, got %T", metadata, value)
    19  	}
    20  	formatMetadataTabular(writer, metadata)
    21  	return nil
    22  }
    23  
    24  // formatMetadataTabular writes a tabular summary of cloud image metadata.
    25  func formatMetadataTabular(writer io.Writer, metadata []MetadataInfo) {
    26  	tw := output.TabWriter(writer)
    27  	print := func(values ...string) {
    28  		fmt.Fprintln(tw, strings.Join(values, "\t"))
    29  	}
    30  	print("SOURCE", "SERIES", "ARCH", "REGION", "IMAGE-ID", "STREAM", "VIRT-TYPE", "STORAGE-TYPE")
    31  
    32  	for _, m := range metadata {
    33  		print(m.Source, m.Series, m.Arch, m.Region, m.ImageId, m.Stream, m.VirtType, m.RootStorageType)
    34  	}
    35  	tw.Flush()
    36  }