Documentation
¶
Overview ¶
Package cmdutil provides utilities for formatting CLI output.
Index ¶
- Constants
- Variables
- func ErrPrintf(msg string, a ...interface{})
- func FormatDuration(dur time.Duration) string
- func LongestFieldFromColumn(rows [][]string, colIdx int) string
- func Print(a ...interface{})
- func Printf(msg string, a ...interface{})
- func Println(a ...interface{})
- func Prompt(msg string, parser InputParser) (interface{}, error)
- func SafeErrPrintf(msg string, a ...interface{})
- func SafePrint(a ...interface{})
- func SafePrintf(msg string, a ...interface{})
- func SafePrintln(a ...interface{})
- type ColumnHeader
- type InputParser
- type Marshaller
- type Pool
- type Table
- type TextMarshaler
- type YamlMarshaler
Constants ¶
const ( // JSON represents the json marshaller JSON = "json" // YAML represents the YAML marshaller YAML = "yaml" // TEXT represents an easily greppable text format TEXT = "text" )
Variables ¶
var ColoredStderr io.Writer = color.Error
ColoredStderr represents a color supporting writer for Stderr
var NewClient = func() client.Client { return client.ForUNIXSocket(config.Socket) }
NewClient returns a new Wash client for the given subcommand. Tests can set NewClient to a stub that returns a mock client.
var Stderr io.Writer = os.Stderr
Stderr represents Stderr
var Stdout io.Writer = os.Stdout
Stdout represents Stdout
Functions ¶
func ErrPrintf ¶
func ErrPrintf(msg string, a ...interface{})
ErrPrintf formats and prints the provided format string and args on stderr and colors the output red.
func FormatDuration ¶
FormatDuration formats a duration as `[[dd-]hh:]mm:ss` according to http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html.
func LongestFieldFromColumn ¶
LongestFieldFromColumn returns the longest string for a particular column index from the provided table.
func Print ¶
func Print(a ...interface{})
Print is a wrapper to fmt.Print that prints to cmdutil.Stdout
func Printf ¶
func Printf(msg string, a ...interface{})
Printf is a wrapper to fmt.Printf that prints to cmdutil.Stdout
func Println ¶
func Println(a ...interface{})
Println is a wrapper to fmt.Println that prints to cmdutil.Stdout
func Prompt ¶
func Prompt(msg string, parser InputParser) (interface{}, error)
Prompt prints the supplied message, waits for input on stdin, then passes the input over to the supplied parser. The actual prompt displayed to the user is "{msg} ".
func SafeErrPrintf ¶
func SafeErrPrintf(msg string, a ...interface{})
SafeErrPrintf is a thread-safe wrapper to ErrPrintf
func SafePrintf ¶
func SafePrintf(msg string, a ...interface{})
SafePrintf is a thread-safe wrapper to Printf
func SafePrintln ¶
func SafePrintln(a ...interface{})
SafePrintln is a thread-safe wrapper to Println
Types ¶
type ColumnHeader ¶
type ColumnHeader struct {
ShortName, FullName string
}
ColumnHeader describes a short and long name for a column.
type InputParser ¶
InputParser represents a parser that parses input passed into Prompt.
var YesOrNoP InputParser = func(input string) (confirmed interface{}, err error) { confirmed = len(input) > 0 && (input[0] == 'y' || input[0] == 'Y') return }
YesOrNoP parses input representing confirmation. confirmed (bool) is true if the input starts with "y" or "Y".
type Marshaller ¶
Marshaller is a type that marshals a given value
func NewMarshaller ¶
func NewMarshaller(format string) (Marshaller, error)
NewMarshaller returns a marshaller that marshals values into the specified format. Currently only JSON or YAML are supported.
All non-JSON marshallers have a default implementation of
"Marshal to JSON" => "Unmarshal the JSON" => "Marshal to <format>"
(the first two steps are effectively "Marshal to a a JSON map/array/value Go type" so that people don't have to implement multiple Marshaler interfaces).
For types that have their own MarshalJSON implementation, this could be a problem because the "Unmarshal the JSON" step unmarshals the data into a different type (so that the custom MarshalJSON implementation is not called). Thus, these types may need to implement the format-specific Marshaler interfaces:
- For YAML, this is cmdutil.YamlMarshaler
- For TEXT, this is cmdutil.TextMarshaler
func (Marshaller) Marshal ¶
func (m Marshaller) Marshal(v interface{}) (string, error)
Marshal marshals the given value
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a worker pool to limit work-in-progress and wait for a dynamic batch of work to complete. It uses WorkerPool to limit how many tasks run at once, and a wait group to know when all queued work is complete. Because the queue is dynamic, we need a wait group to tell us when all potential work is complete before we tell the pool to stop accepting new work and shutdown.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table represents a formatted table. Use the NewTable* functions to create your Table objects.
func NewTableWithHeaders ¶
func NewTableWithHeaders(headers []ColumnHeader, rows [][]string) *Table
NewTableWithHeaders creates a new Table object with the given headers and rows
type TextMarshaler ¶
TextMarshaler is a type that can be marshaled into Text output.
For structured data, text output prefixes each line with the entire key path (using .KEY for map indexing and .N for array indexing) to make it more greppable. For example, given something like
AppArmorProfile: Args: - redis-server Config: AttachStdout: false Cmd: - redis-server
Its Text output would be:
AppArmorProfile: Args.0: redis-server Config.AttachStdout: false Config.Cmd.0: redis-server
type YamlMarshaler ¶
YamlMarshaler is a type that can be marshalled into YAML