github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/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 13 "github.com/juju/juju/cmd/output" 14 ) 15 16 func formatMetadataListTabular(writer io.Writer, value interface{}) error { 17 metadata, ok := value.([]MetadataInfo) 18 if !ok { 19 return errors.Errorf("expected value of type %T, got %T", metadata, value) 20 } 21 formatMetadataTabular(writer, metadata) 22 return nil 23 } 24 25 // formatMetadataTabular writes a tabular summary of cloud image metadata. 26 func formatMetadataTabular(writer io.Writer, metadata []MetadataInfo) { 27 tw := output.TabWriter(writer) 28 print := func(values ...string) { 29 fmt.Fprintln(tw, strings.Join(values, "\t")) 30 } 31 print("Source", "Series", "Arch", "Region", "Image id", "Stream", "Virt Type", "Storage Type") 32 33 for _, m := range metadata { 34 print(m.Source, m.Series, m.Arch, m.Region, m.ImageId, m.Stream, m.VirtType, m.RootStorageType) 35 } 36 tw.Flush() 37 }