cli

package
v0.0.0-...-057f6e6 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: Apache-2.0 Imports: 8 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Body

func Body(m string) string

Body is an alias for Indent. It takes a message and returns it with indentation.

func Indent

func Indent(m string) string

Indent takes a message and returns it with indentation.

Types

type BodyWriter

type BodyWriter interface {
	Body(string)
	Bodyf(string, ...interface{})
}

BodyWriter is an interface for printers that can print indented sub-steps of a process.

type ErrorWriter

type ErrorWriter interface {
	Error(string)
	Errorf(string, ...interface{})
	Errorln(string)
}

ErrorWriter is an interface for printers that print to a writer that the user expects errors on, such as stderr.

type FormatWriter

type FormatWriter interface {
	// Writers
	Print(string)
	Printf(string, ...interface{})
	Println(string)
	Success(string)
	Successf(string, ...interface{})
	Skipped(string)
	Skippedf(string, ...interface{})
	Fail(string)
	Failf(string, ...interface{})
	FailError(error)
	FailWrap(error, string)
	FailCause(error)
	FailWrapCause(error, string)
	Failt(string, string)
	Failtf(string, string, ...interface{})

	BodyWriter
	TitleWriter
	ErrorWriter
	WarnWriter

	HR()
	ErrorHeader(string)

	Confirm(string) (bool, error)
	Prompt(string) (string, error)

	// Implement a buffered version of the io.Writer interface
	Writer() io.Writer
	BufferWriter() *bufio.Writer

	// Spinner
	StartSpinner()
	StopSpinner()
}

FormatWriter is a writer interface that includes formatting helpers

type TitleWriter

type TitleWriter interface {
	Title(string)
	Titlef(string, ...interface{})
}

TitleWriter is an interface for printers that can print indented sub-steps of a process.

type WarnWriter

type WarnWriter interface {
	Warn(string)
	Warnf(string, ...interface{})
	Warnln(string)
	WarnError(error)
	LongWarningln(string)
}

WarnWriter is an interface for printers that can printed warnings

type Writer

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

Writer is the default implementation of of the cli FormatWriter interface

func NewWriter

func NewWriter(w io.Writer, e io.Writer, r io.Reader) *Writer

NewWriter takes and io.Writer and returns a pointer to an instance of cli.Writer.

func (*Writer) Body

func (w *Writer) Body(text string)

Body outputs an indented line of text

func (*Writer) Bodyf

func (w *Writer) Bodyf(text string, a ...interface{})

Bodyf formats the provided string and then calls Body

func (*Writer) BufferWriter

func (w *Writer) BufferWriter() *bufio.Writer

BufferWriter returns a pointer to the cli.Writer's bufio.Writer

func (*Writer) Confirm

func (w *Writer) Confirm(question string) (bool, error)

Confirm asks the user if they want to take the action defined in the question or not. Ex: Confirm("should we do the thing?") > should we do the thing? (y/n) <waits for stdin>

func (*Writer) Error

func (w *Writer) Error(m string)

Error writes the message to the error writer..

func (*Writer) ErrorHeader

func (w *Writer) ErrorHeader(text string)

ErrorHeader prints an ASCII horizontal rule, then "ERROR: " plus your text and then another hr, like this: ErrorHeader("didn't catch 'em all :'(") -------------------------------------------------------------------------------- ERROR: didn't catch 'em all :'( --------------------------------------------------------------------------------

func (*Writer) Errorf

func (w *Writer) Errorf(m string, f ...interface{})

Errorf formats the message with the format string and writes it to the error writer.

func (*Writer) Errorln

func (w *Writer) Errorln(m string)

Errorln writes the message to the error writer with a newline

func (*Writer) Fail

func (w *Writer) Fail(m string)

Fail formats the message as a failure and writes it to the writer.

func (*Writer) FailCause

func (w *Writer) FailCause(e error)

FailCause prints the error's message and attempts to locate a root cause. In the event a root cause is found that is not the error it will also print the cause.

func (*Writer) FailError

func (w *Writer) FailError(e error)

FailError formats the error's message as a Failure message and writes it to the writer.

func (*Writer) FailWrap

func (w *Writer) FailWrap(e error, m string)

FailWrap wraps the error's message and outputs it to the writer as a Failure message.

func (*Writer) FailWrapCause

func (w *Writer) FailWrapCause(e error, m string)

FailWrapCause wraps the error's message and prints the error message. In the event a root cause is found that is not the error it will also print the cause.

func (*Writer) Failf

func (w *Writer) Failf(m string, f ...interface{})

Failf formats the message with the format string and writes it to the writer as a Failure message.

func (*Writer) Failt

func (w *Writer) Failt(errType string, m string)

Failt prints the error message with an error type header and message

func (*Writer) Failtf

func (w *Writer) Failtf(errType string, m string, f ...interface{})

Failtf prints the error message with an error type header and with a formatted message

func (*Writer) HR

func (w *Writer) HR()

HR prints a horizontal rule (80 chars of "-")

func (*Writer) LongWarningln

func (w *Writer) LongWarningln(m string)

LongWarningln colors the output as a warning but does not append any text

func (*Writer) NewSpinner

func (w *Writer) NewSpinner() *spinner.Spinner

func (*Writer) NewSpinnerWithTab

func (w *Writer) NewSpinnerWithTab() *spinner.Spinner

func (*Writer) Print

func (w *Writer) Print(m string)

Print writes the message to the writer.

func (*Writer) Printf

func (w *Writer) Printf(m string, f ...interface{})

Printf formats the message with the format string and writes it to the writer.

func (*Writer) Println

func (w *Writer) Println(m string)

Println writes the message to the writer with a newline

func (*Writer) Prompt

func (w *Writer) Prompt(promptText string) (response string, err error)

func (*Writer) Skipped

func (w *Writer) Skipped(m string)

Skipped formats the message to a Skipped message and writes it to the writer.

func (*Writer) Skippedf

func (w *Writer) Skippedf(m string, f ...interface{})

Skippedf formats the message using the format string and writes it to the writer as a Skipped message.

func (*Writer) StartSpinner

func (w *Writer) StartSpinner()

StartSpinner starts the CLI spinner

func (*Writer) StopSpinner

func (w *Writer) StopSpinner()

StopSpinner stops the CLI spinner

func (*Writer) Success

func (w *Writer) Success(m string)

Success formats the message to a Success message and writes it to the writer.

func (*Writer) Successf

func (w *Writer) Successf(m string, f ...interface{})

Successf formats the message using the format string and writes it to the writer as a Success message.

func (*Writer) Title

func (w *Writer) Title(text string)

Title outputs an un-indented line of text newlines before and after.

func (*Writer) Titlef

func (w *Writer) Titlef(text string, a ...interface{})

Titlef formats the provided string and then calls Title

func (*Writer) Warn

func (w *Writer) Warn(m string)

Warn formats the message as a warning and writes it to the writer.

func (*Writer) WarnError

func (w *Writer) WarnError(e error)

WarnError formats the error's message as a Warning message and writes it to the writer.

func (*Writer) Warnf

func (w *Writer) Warnf(m string, f ...interface{})

Warnf formats the message with the format string and writes it to the writer as a Warning message.

func (*Writer) Warnln

func (w *Writer) Warnln(m string)

Warnln formats the messages as a warning and writes it to the writer, appending a newline.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Writer implements the io.Writer interface

func (*Writer) Writer

func (w *Writer) Writer() io.Writer

Writer returns a pointer to the cli.Writer's io.Writer

Jump to

Keyboard shortcuts

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