Documentation
¶
Index ¶
- Constants
- Variables
- func BuildDebugStrFromHTTPRequest(req *http.Request, includeHeaders []string) ([]string, error)
- func BuildDebugStrFromHTTPResponse(resp *http.Response, includeHeaders []string) ([]string, error)
- func BuildDebugStrFromMap(inputMap map[string]any) string
- func BuildDebugStrFromSlice(inputSlice []string) string
- func RequestResponseCapturer(p *Printer, includeHeaders []string) config.Middleware
- type Level
- type Printer
- func (p *Printer) Debug(level Level, msg string, args ...any)
- func (p *Printer) DebugInputModel(model any)
- func (p *Printer) Error(msg string, args ...any)
- func (p *Printer) Info(msg string, args ...any)
- func (p *Printer) IsVerbosityDebug() bool
- func (p *Printer) IsVerbosityError() bool
- func (p *Printer) IsVerbosityInfo() bool
- func (p *Printer) IsVerbosityWarning() bool
- func (p *Printer) Outputf(msg string, args ...any)
- func (p *Printer) Outputln(msg string)
- func (p *Printer) PagerDisplay(content string) error
- func (p *Printer) PromptForConfirmation(prompt string) error
- func (p *Printer) PromptForEnter(prompt string) error
- func (p *Printer) PromptForPassword(prompt string) (string, error)
- func (p *Printer) Warn(msg string, args ...any)
Constants ¶
const ( DebugLevel Level = "debug" InfoLevel Level = "info" WarningLevel Level = "warning" ErrorLevel Level = "error" JSONOutputFormat = "json" PrettyOutputFormat = "pretty" NoneOutputFormat = "none" YAMLOutputFormat = "yaml" )
Variables ¶
Functions ¶
func BuildDebugStrFromHTTPRequest ¶ added in v0.4.0
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
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 BuildDebugStrFromMap ¶ added in v0.4.0
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
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 Printer ¶
func NewPrinter ¶
func NewPrinter() *Printer
NewPrinter creates a new printer, including setting up the default logger.
func (*Printer) Debug ¶
Print a Debug level log through the "slog" package. If the verbosity level is not Debug, it does nothing
func (*Printer) DebugInputModel ¶ added in v0.44.0
DebugInputModel prints the given input model in case verbosity level is set to Debug, does nothing otherwise
func (*Printer) Error ¶
Print an Error level output to the defined Err output (falling back to Stderr if not set).
func (*Printer) Info ¶
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
Returns True if the verbosity level is set to Debug, False otherwise.
func (*Printer) IsVerbosityError ¶ added in v0.4.0
Returns True if the verbosity level is set to Error, False otherwise.
func (*Printer) IsVerbosityInfo ¶ added in v0.4.0
Returns True if the verbosity level is set to Info, False otherwise.
func (*Printer) IsVerbosityWarning ¶ added in v0.4.0
Returns True if the verbosity level is set to Warning, False otherwise.
func (*Printer) Outputf ¶
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 ¶
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
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 ¶
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
Prompts the user for confirmation by pressing Enter.
Returns nil if the user presses Enter.
func (*Printer) PromptForPassword ¶ added in v0.5.0
Prompts the user for a password.
Returns the password that was given, otherwise returns error