print

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DebugLevel   Level = "debug"
	InfoLevel    Level = "info"
	WarningLevel Level = "warning"
	ErrorLevel   Level = "error"

	JSONOutputFormat   = "json"
	PrettyOutputFormat = "pretty"
	NoneOutputFormat   = "none"
	YAMLOutputFormat   = "yaml"
)

Variables

View Source
var (
	WhiteBold  = color.New(color.FgHiWhite, color.Bold).SprintFunc()
	RedBold    = color.New(color.FgHiRed, color.Bold).SprintFunc()
	YellowBold = color.New(color.FgHiYellow, color.Bold).SprintFunc()
)

Functions

func BuildDebugStrFromHTTPRequest added in v0.4.0

func BuildDebugStrFromHTTPRequest(req *http.Request, includeHeaders []string) ([]string, error)

BuildDebugStrFromHTTPRequest converts an HTTP request to a user-friendly string representation. This function also receives a list of headers to include in the output, if empty, the default headers are used. The return value is a list of strings that should be printed separately.

func BuildDebugStrFromHTTPResponse added in v0.4.0

func BuildDebugStrFromHTTPResponse(resp *http.Response, includeHeaders []string) ([]string, error)

BuildDebugStrFromHTTPResponse converts an HTTP response to a user-friendly string representation. This function also receives a list of headers to include in the output, if empty, the default headers are used. The return value is a list of strings that should be printed separately.

func BuildDebugStrFromInputModel added in v0.4.0

func BuildDebugStrFromInputModel(model any) (string, error)

BuildDebugStrFromInputModel converts an input model to a user-friendly string representation. This function converts the input model to a map, removes empty values, and generates a string representation of the map. The purpose of this function is to provide a more readable output than the default JSON representation. It is particularly useful when outputting to the slog logger, as the JSON format with escaped quotes does not look good.

func BuildDebugStrFromMap added in v0.4.0

func BuildDebugStrFromMap(inputMap map[string]any) string

BuildDebugStrFromMap converts a map to a user-friendly string representation. This function removes empty values and generates a string representation of the map. The string representation is in the format: [key1: value1, key2: value2, ...] The keys are ordered alphabetically to make the output deterministic.

func BuildDebugStrFromSlice added in v0.4.0

func BuildDebugStrFromSlice(inputSlice []string) string

BuildDebugStrFromSlice converts a slice to a user-friendly string representation.

func RequestResponseCapturer added in v0.4.0

func RequestResponseCapturer(p *Printer, includeHeaders []string) config.Middleware

RequestResponseCapturer is a middleware that captures the request and response of an HTTP request. Receives a printer and a list of headers to include in the output If the list of headers is empty, the default headers are used. The printer is used to print the captured data.

Types

type Level

type Level string

type Printer

type Printer struct {
	Cmd       *cobra.Command
	Verbosity Level
}

func NewPrinter

func NewPrinter() *Printer

Creates a new printer, including setting up the default logger.

func (*Printer) Debug

func (p *Printer) Debug(level Level, msg string, args ...any)

Print a Debug level log through the "slog" package. If the verbosity level is not Debug, it does nothing

func (*Printer) Error

func (p *Printer) Error(msg string, args ...any)

Print an Error level output to the defined Err output (falling back to Stderr if not set).

func (*Printer) Info

func (p *Printer) Info(msg string, args ...any)

Print an Info level output to the defined Err output (falling back to Stderr if not set). If the verbosity level is not Debug or Info, it does nothing.

func (*Printer) IsVerbosityDebug added in v0.4.0

func (p *Printer) IsVerbosityDebug() bool

Returns True if the verbosity level is set to Debug, False otherwise.

func (*Printer) IsVerbosityError added in v0.4.0

func (p *Printer) IsVerbosityError() bool

Returns True if the verbosity level is set to Error, False otherwise.

func (*Printer) IsVerbosityInfo added in v0.4.0

func (p *Printer) IsVerbosityInfo() bool

Returns True if the verbosity level is set to Info, False otherwise.

func (*Printer) IsVerbosityWarning added in v0.4.0

func (p *Printer) IsVerbosityWarning() bool

Returns True if the verbosity level is set to Warning, False otherwise.

func (*Printer) Outputf

func (p *Printer) Outputf(msg string, args ...any)

Print an output using Printf to the defined output (falling back to Stderr if not set). If output format is set to none, it does nothing

func (*Printer) Outputln

func (p *Printer) Outputln(msg string)

Print an output using Println to the defined output (falling back to Stderr if not set). If output format is set to none, it does nothing

func (*Printer) PagerDisplay added in v0.2.3

func (p *Printer) PagerDisplay(content string) error

Shows the content in the command's stdout using the "less" command If output format is set to none, it does nothing

func (*Printer) PromptForConfirmation

func (p *Printer) PromptForConfirmation(prompt string) error

Prompts the user for confirmation.

Returns nil only if the user (explicitly) answers positive. Returns ErrAborted if the user answers negative.

func (*Printer) PromptForEnter added in v0.3.0

func (p *Printer) PromptForEnter(prompt string) error

Prompts the user for confirmation by pressing Enter.

Returns nil if the user presses Enter.

func (*Printer) PromptForPassword added in v0.5.0

func (p *Printer) PromptForPassword(prompt string) (string, error)

Prompts the user for a password.

Returns the password that was given, otherwise returns error

func (*Printer) Warn

func (p *Printer) Warn(msg string, args ...any)

Print a Warn level output to the defined Err output (falling back to Stderr if not set). If the verbosity level is not Debug, Info, or Warn, it does nothing.

Jump to

Keyboard shortcuts

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