Add some more docs.

This commit is contained in:
Brendan Burns 2014-06-08 21:05:43 -07:00
parent 3e211272a7
commit f204bd52bc

View File

@ -1,7 +1,6 @@
package cloudcfg package cloudcfg
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
@ -12,17 +11,21 @@ import (
"gopkg.in/v1/yaml" "gopkg.in/v1/yaml"
) )
// ResourcePrinter is an interface that knows how to print API resources
type ResourcePrinter interface { type ResourcePrinter interface {
// Print receives an arbitrary JSON body, formats it and prints it to a writer
Print(string, io.Writer) error Print(string, io.Writer) error
} }
// Identity printer simply copies the body out to the output stream
type IdentityPrinter struct{} type IdentityPrinter struct{}
func (i *IdentityPrinter) Print(data string, w io.Writer) error { func (i *IdentityPrinter) Print(data string, w io.Writer) error {
_, err := io.Copy(w, bytes.NewBufferString(data)) _, err := fmt.Fprint(w, data)
return err return err
} }
// YAMLPrinter parses JSON, and re-formats as YAML
type YAMLPrinter struct{} type YAMLPrinter struct{}
func (y *YAMLPrinter) Print(data string, w io.Writer) error { func (y *YAMLPrinter) Print(data string, w io.Writer) error {
@ -38,6 +41,7 @@ func (y *YAMLPrinter) Print(data string, w io.Writer) error {
return err return err
} }
// HumanReadablePrinter attempts to provide more elegant output
type HumanReadablePrinter struct{} type HumanReadablePrinter struct{}
var taskColumns = []string{"Name", "Image(s)", "Host", "Labels"} var taskColumns = []string{"Name", "Image(s)", "Host", "Labels"}