func (c *SuperCommand) handleErrorForMachineFormats(ctx *Context) error {
	// If an output format was used on stdout already we can omit correction
	// of the machine output.
	if !ctx.IsSerial() || ctx.outputFormatUsed {
		return nil
	}

	formatFlag := c.commonflags.Lookup("format")
	if formatFlag == nil {
		return nil
	}
	formatName := formatFlag.Value.String()
	typeFormatter, ok := DefaultFormatters[formatName]
	if !ok {
		return errors.Errorf("missing formatter %q", formatName)
	}
	// Although this code handles errors for machine formats, the actual empty
	// type should be written to stdout. This allows consumers of the output to
	// correctly handle the resulting empty value.
	// If we place it into stderr, it means that you can never add any more
	// additional information to stderr, even if it helps the user.
	return typeFormatter.Formatter(ctx.Stdout, struct{}{})
}
// handleErrorForMachineFormats attempts to handle fatal errors when using
// formatting directives.
// If the formatting directive is what we consider a machine format (yaml or
// json), then we attempt to output nothing for that format. An example of this
// would be; for json, that would be {}.
// No additional writes to stdout or stderr should be performed when a
// successful format lookup is done, otherwise return errors from a unsuccessful
// lookup.
handleErrorForMachineFormats attempts to handle fatal errors when using
formatting directives.
If the formatting directive is what we consider a machine format (yaml or
json), then we attempt to output nothing for that format. An example of this
would be; for json, that would be {}.
No additional writes to stdout or stderr should be performed when a
successful format lookup is done, otherwise return errors from a unsuccessful
lookup.
// handleErrorForMachineFormats attempts to handle fatal errors when using // formatting directives . // If the formatting directive is what we consider a machine format ( yaml or // json ) then we attempt to output nothing for that format . An example of this // would be ; for json that would be {} . // No additional writes to stdout or stderr should be performed when a // successful format lookup is done otherwise return errors from a unsuccessful // lookup .
func (c *SuperCommand) handleErrorForMachineFormats(ctx *Context) error {
	if !ctx.IsSerial() || ctx.outputFormatUsed {
		return nil
	}
	formatFlag := c.commonflags.Lookup("format")
	if formatFlag == nil {
		return nil
	}
	formatName := formatFlag.Value.String()
	typeFormatter, ok := DefaultFormatters[formatName]
	if !ok {
		return errors.Errorf("missing formatter %q", formatName)
	}
	return typeFormatter.Formatter(ctx.Stdout, struct{}{})
}
func ( c * SuperCommand ) handleErrorForMachineFormats ( ctx * Context ) error { if ! ctx . IsSerial ( ) || ctx . outputFormatUsed { return nil } formatFlag := c . commonflags . Lookup ( " " ) if formatFlag == nil { return nil } formatName := formatFlag . Value . String ( ) typeFormatter , ok := DefaultFormatters [ formatName ] if ! ok { return errors . Errorf ( " " , formatName ) } return typeFormatter . Formatter ( ctx . Stdout , struct { } { } ) }
handleErrorForMachineFormats attempts to handle fatal errors when using
formatting directives.
handleErrorForMachineFormats attempts to handle fatal errors when using formatting directives .
// If an output format was used on stdout already we can omit correction // of the machine output. // Although this code handles errors for machine formats, the actual empty // type should be written to stdout. This allows consumers of the output to // correctly handle the resulting empty value. // If we place it into stderr, it means that you can never add any more // additional information to stderr, even if it helps the user.