replyfmt

package
v0.28.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package replyfmt formats Replies for presentation to users

Index

Constants

View Source
const (
	DisplayDDL = DisplayMode(iota)
	DisplayOK
	DisplayFailed
	DisplayAll
	DisplayNone
)
View Source
const (
	// UnknownFormat is an unknown format
	UnknownFormat = OutputFormat(iota)

	// ConsoleFormat is a format suitable for displaying on the console
	ConsoleFormat
)

Variables

This section is empty.

Functions

func FormatAggregates

func FormatAggregates(w io.Writer, f OutputFormat, action ActionDDL, opts ...Option) error

func FormatReply

func FormatReply(w io.Writer, f OutputFormat, action ActionDDL, sender string, reply *client.RPCReply, opts ...Option) error

Types

type ActionDDL added in v0.16.0

type ActionDDL interface {
	SetOutputDefaults(results map[string]any)
	AggregateResult(result map[string]any) error
	AggregateResultJSON(jres []byte) error
	AggregateSummaryJSON() ([]byte, error)
	GetOutput(string) (*common.OutputItem, bool)
	AggregateSummaryFormattedStrings() (map[string][]string, error)
	DisplayMode() string
	OutputNames() []string
}

type ConsoleFormatter

type ConsoleFormatter struct {
	// contains filtered or unexported fields
}

func NewConsoleFormatter

func NewConsoleFormatter(opts ...Option) *ConsoleFormatter

func (*ConsoleFormatter) FormatAggregates

func (c *ConsoleFormatter) FormatAggregates(w io.Writer, action ActionDDL) error

func (*ConsoleFormatter) FormatReply

func (c *ConsoleFormatter) FormatReply(w io.Writer, action ActionDDL, sender string, reply *client.RPCReply) error

func (*ConsoleFormatter) SetDisplay

func (c *ConsoleFormatter) SetDisplay(m DisplayMode)

func (*ConsoleFormatter) SetSilent

func (c *ConsoleFormatter) SetSilent()

func (*ConsoleFormatter) SetVerbose

func (c *ConsoleFormatter) SetVerbose()

type DisplayMode

type DisplayMode uint8

DisplayMode overrides the DDL display hints

type Formatter

type Formatter interface {
	FormatReply(w io.Writer, action ActionDDL, sender string, reply *client.RPCReply) error
	FormatAggregates(w io.Writer, action ActionDDL) error

	SetVerbose()
	SetSilent()
	SetDisplay(mode DisplayMode)
}

Formatter formats and writes a reply into the bufio writer

type Logger added in v0.17.0

type Logger interface {
	Debugf(format string, args ...any)
	Infof(format string, args ...any)
	Warnf(format string, args ...any)
	Errorf(format string, args ...any)
	Fatalf(format string, args ...any)
	Panicf(format string, args ...any)
}

type Option

type Option func(f Formatter) error

Option configures a formatter

func ConsoleNoColor

func ConsoleNoColor() Option

ConsoleNoColor disables color in the console formatter

func Display

func Display(d DisplayMode) Option

func Silent

func Silent() Option

Silent sets verbose output mode

func Verbose

func Verbose() Option

Verbose sets verbose output mode

type OutputFormat

type OutputFormat uint8

OutputFormat is the format of reply desired

type RPCReply added in v0.16.0

type RPCReply struct {
	Sender string `json:"sender"`
	*rpc.RPCReply
}

type RPCResults added in v0.16.0

type RPCResults struct {
	Agent       string          `json:"agent"`
	Action      string          `json:"action"`
	Replies     []*RPCReply     `json:"replies"`
	Stats       *rpc.Stats      `json:"-"`
	ParsedStats *RPCStats       `json:"request_stats"`
	Summaries   json.RawMessage `json:"summaries"`
}

func (*RPCResults) CalculateAggregates added in v0.27.0

func (r *RPCResults) CalculateAggregates(action ActionDDL) error

func (*RPCResults) RenderJSON added in v0.16.0

func (r *RPCResults) RenderJSON(w io.Writer, action ActionDDL) (err error)

func (*RPCResults) RenderNames added in v0.25.0

func (r *RPCResults) RenderNames(w io.Writer, jsonFormat bool, sortNames bool) error

RenderNames renders a list of names of successful senders TODO: should become a reply format formatter maybe

func (*RPCResults) RenderTXT added in v0.16.0

func (r *RPCResults) RenderTXT(w io.Writer, action ActionDDL, verbose bool, silent bool, display DisplayMode, colorize bool, log Logger) (err error)

func (*RPCResults) RenderTXTFooter added in v0.17.0

func (r *RPCResults) RenderTXTFooter(w io.Writer, verbose bool)

func (*RPCResults) RenderTable added in v0.17.0

func (r *RPCResults) RenderTable(w io.Writer, action ActionDDL) (err error)

RenderTable renders a table of outputs TODO: should become a reply format formatter, but those lack a prepare phase to print headers etc

type RPCStats added in v0.16.0

type RPCStats struct {
	RequestID           string        `json:"requestid"`
	NoResponses         []string      `json:"no_responses"`
	UnexpectedResponses []string      `json:"unexpected_responses"`
	DiscoveredCount     int           `json:"discovered"`
	FailCount           int           `json:"failed"`
	OKCount             int           `json:"ok"`
	ResponseCount       int           `json:"responses"`
	PublishTime         time.Duration `json:"publish_time"`
	RequestTime         time.Duration `json:"request_time"`
	DiscoverTime        time.Duration `json:"discover_time"`
	StartTime           time.Time     `json:"start_time_utc"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL