Documentation ¶
Index ¶
- Constants
- Variables
- func AskYesNo(w io.Writer, prompt string, r io.Reader) (bool, error)
- func Break(w io.Writer)
- func Description(w io.Writer, term, description string)
- func Error(w io.Writer, format string, args ...interface{})
- func Indent(w io.Writer, indent uint, format string, args ...interface{})
- func Info(w io.Writer, format string, args ...interface{})
- func Input(w io.Writer, prefix string, r io.Reader, validators ...func(string) error) (string, error)
- func InputSecure(w io.Writer, prefix string, r io.Reader, validators ...func(string) error) (string, error)
- func LastFullLine(s string) string
- func Output(w io.Writer, format string, args ...interface{})
- func PrintBackend(out io.Writer, prefix string, b *fastly.Backend)
- func PrintDictionary(out io.Writer, prefix string, d *fastly.Dictionary)
- func PrintDictionaryItem(out io.Writer, prefix string, d *fastly.DictionaryItem)
- func PrintDictionaryItemKV(out io.Writer, prefix string, d *fastly.DictionaryItem)
- func PrintHealthCheck(out io.Writer, prefix string, h *fastly.HealthCheck)
- func PrintService(out io.Writer, prefix string, s *fastly.Service)
- func PrintVersion(out io.Writer, indent string, v *fastly.Version)
- func Spin(ctx context.Context, frames []rune, interval time.Duration, target Ticker) error
- func Success(w io.Writer, format string, args ...interface{})
- func Warning(w io.Writer, format string, args ...interface{})
- func Wrap(text string, width uint) string
- func WrapIndent(s string, lim uint, indent uint) string
- type InteractiveProgress
- type NullProgress
- type Option
- type Progress
- type ProgressOptions
- type QuietProgress
- type Table
- type Ticker
- type VerboseProgress
Constants ¶
const DefaultTextWidth = 90
DefaultTextWidth is the width that should be passed to Wrap for most general-purpose blocks of text intended for the user.
Variables ¶
var Bold = color.New(color.Bold).SprintFunc()
Bold is a Sprint-class function that makes the arguments bold.
BoldGreen is a Sprint-class function that makes the arguments bold and green.
BoldRed is a Sprint-class function that makes the arguments bold and red.
BoldYellow is a Sprint-class function that makes the arguments bold and yellow.
var Reset = color.New(color.Reset).SprintFunc()
Reset is a Sprint-class function that resets the color for the arguments.
Functions ¶
func AskYesNo ¶ added in v1.4.0
AskYesNo is similar to Input, but the line read is coerced to one of true (yes and its variants) or false (no, its variants and anything else) on success.
func Break ¶
Break simply writes a newline to the writer. It's intended to be used between blocks of text that would otherwise be adjacent, a sort of semantic markup.
func Description ¶ added in v0.3.0
Description formats the output of a description item. A description item consists of a `term` and a `description`. Emphasis is placed on the `description` using Bold(). For example:
To compile the package, run: fastly compute build
func Indent ¶ added in v0.39.2
Indent writes the help text to the writer using WrapIndent with DefaultTextWidth, suffixed by a newlines. It's intended to be used to provide detailed information, context, or help to the user.
func Input ¶
func Input(w io.Writer, prefix string, r io.Reader, validators ...func(string) error) (string, error)
Input prints the prefix to the writer, and then reads a single line from the reader, trimming writespace. The received line is passed to the validators, and if any of them return a non-nil error, the error is printed to the writer, and the input process happens again. Otherwise, the line is returned to the caller.
Input is intended to be used to take interactive input from the user.
func InputSecure ¶
func InputSecure(w io.Writer, prefix string, r io.Reader, validators ...func(string) error) (string, error)
InputSecure is like Input but doesn't echo input back to the terminal, if and only if r is os.Stdin.
func LastFullLine ¶
LastFullLine returns the last full \n delimited line in s. That is, s must contain at least one \n for LastFullLine to return anything.
func Output ¶
Output writes the help text to the writer using Wrap with DefaultTextWidth, suffixed by a newlines. It's intended to be used to provide detailed information, context, or help to the user.
func PrintBackend ¶
PrintBackend pretty prints a fastly.Backend structure in verbose format to a given io.Writer. Consumers can provide a prefix string which will be used as a prefix to each line, useful for indentation.
func PrintDictionary ¶ added in v0.21.0
func PrintDictionary(out io.Writer, prefix string, d *fastly.Dictionary)
PrintDictionary pretty prints a fastly.Dictionary structure in verbose format to a given io.Writer. Consumers can provide a prefix string which will be used as a prefix to each line, useful for indentation.
func PrintDictionaryItem ¶ added in v0.21.0
func PrintDictionaryItem(out io.Writer, prefix string, d *fastly.DictionaryItem)
PrintDictionaryItem pretty prints a fastly.DictionaryInfo structure in verbose format to a given io.Writer. Consumers can provide a prefix string which will be used as a prefix to each line, useful for indentation.
func PrintDictionaryItemKV ¶ added in v0.21.0
func PrintDictionaryItemKV(out io.Writer, prefix string, d *fastly.DictionaryItem)
PrintDictionaryItemKV pretty prints only the key/value pairs from a dictionary item.
func PrintHealthCheck ¶
func PrintHealthCheck(out io.Writer, prefix string, h *fastly.HealthCheck)
PrintHealthCheck pretty prints a fastly.HealthCheck structure in verbose format to a given io.Writer. Consumers can provide a prefix string which will be used as a prefix to each line, useful for indentation.
func PrintService ¶
PrintService pretty prints a fastly.Service structure in verbose format to a given io.Writer. Consumers can provide a prefix string which will be used as a prefix to each line, useful for indentation.
func PrintVersion ¶
PrintVersion pretty prints a fastly.Version structure in verbose format to a given io.Writer. Consumers can provide a prefix string which will be used as a prefix to each line, useful for indentation.
func Spin ¶
Spin calls Tick on the target with the relevant frame every interval. It returns when context is canceled, so should be called in its own goroutine.
func Wrap ¶
Wrap a string at word boundaries with a maximum line length of width. Each newline-delimited line in the text is trimmed of whitespace before being added to the block for wrapping, which means strings can be declared in the source code with whatever leading indentation looks best in context. For example,
Wrap(` Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Dolor sed viverra ipsum nunc aliquet bibendum enim. In massa tempor nec feugiat. `, 40)
Produces the output string
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Dolor sed viverra ipsum nunc aliquet bibendum enim. In massa tempor nec feugiat.
Types ¶
type InteractiveProgress ¶ added in v0.38.0
type InteractiveProgress struct {
// contains filtered or unexported fields
}
InteractiveProgress is an implementation of Progress that includes a spinner at the beginning of each Step, and where newline-delimited lines written via Write overwrite the current step line in the output.
func NewInteractiveProgress ¶ added in v0.38.0
func NewInteractiveProgress(output io.Writer, options ...Option) *InteractiveProgress
NewInteractiveProgress returns a InteractiveProgress outputting to the writer.
func (*InteractiveProgress) Done ¶ added in v0.38.0
func (p *InteractiveProgress) Done()
Done implements the Progress interface.
func (*InteractiveProgress) Fail ¶ added in v0.38.0
func (p *InteractiveProgress) Fail()
Fail implements the Progress interface.
func (*InteractiveProgress) Step ¶ added in v0.38.0
func (p *InteractiveProgress) Step(msg string)
Step implements the Progress interface.
func (*InteractiveProgress) Tick ¶ added in v0.38.0
func (p *InteractiveProgress) Tick(r rune)
Tick implements the Progress interface.
type NullProgress ¶ added in v0.3.0
type NullProgress struct {
// contains filtered or unexported fields
}
NullProgress is an implementation of Progress which discards everything written into it and produces no output.
func NewNullProgress ¶ added in v0.3.0
func NewNullProgress() *NullProgress
NewNullProgress returns a NullProgress.
func (*NullProgress) Done ¶ added in v0.3.0
func (p *NullProgress) Done()
Done implements the Progress interface. It's a no-op.
func (*NullProgress) Fail ¶ added in v0.3.0
func (p *NullProgress) Fail()
Fail implements the Progress interface. It's a no-op.
func (*NullProgress) Step ¶ added in v0.3.0
func (p *NullProgress) Step(msg string)
Step implements the Progress interface.
func (*NullProgress) Tick ¶ added in v0.3.0
func (p *NullProgress) Tick(r rune)
Tick implements the Progress interface. It's a no-opt
type Option ¶ added in v1.4.0
type Option func(*ProgressOptions)
Option represents optional configuration for a Progress type.
type Progress ¶
Progress is a producer contract, abstracting over the quiet and verbose Progress types. Consumers may use a Progress value in their code, and assign it based on the presence of a -v, --verbose flag. Callers are expected to call Step for each new major step of their procedural code, and Write with the verbose or detailed output of those steps. Callers must eventually call either Done or Fail, to signal success or failure respectively.
func NewProgress ¶ added in v0.38.0
NewProgress returns a Progress based on the given verbosity level or whether the current process is running in a terminal environment.
func ResetProgress ¶ added in v1.4.0
ResetProgress wraps the NewProgress and passes through a restart option.
NOTE: A Progress sometimes needs to be marked as Done() so that other output can be printed to the terminal (otherwise the Progress will always overwrite the output). If we just call NewProgress again then we'll see an 'Initializing...' message which looks odd. Instead we can now reset the progress instead which will simply tell the Progress type not to set that step header.
type ProgressOptions ¶ added in v1.4.0
type ProgressOptions struct {
// contains filtered or unexported fields
}
type QuietProgress ¶
type QuietProgress struct {
// contains filtered or unexported fields
}
QuietProgress is an implementation of Progress that attempts to be quiet in it's output. I.e. it only prints each Step as it progresses and discards any intermediary writes between steps. No spinners are used, therefore it's useful for non-TTY environiments, such as CI.
func NewQuietProgress ¶
func NewQuietProgress(output io.Writer) *QuietProgress
NewQuietProgress returns a QuietProgress outputting to the writer.
func (*QuietProgress) Done ¶
func (p *QuietProgress) Done()
Done implements the Progress interface. It's a no-op.
func (*QuietProgress) Fail ¶
func (p *QuietProgress) Fail()
Fail implements the Progress interface. It's a no-op.
func (*QuietProgress) Step ¶
func (p *QuietProgress) Step(msg string)
Step implements the Progress interface.
func (*QuietProgress) Tick ¶
func (p *QuietProgress) Tick(r rune)
Tick implements the Progress interface. It's a no-op.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table wraps an instance of a tabwriter and provides helper methods to easily create a table, add a header, add rows and print to the writer.
func (*Table) AddHeader ¶
func (t *Table) AddHeader(args ...interface{})
AddHeader writes a table header line.
type Ticker ¶
type Ticker interface {
Tick(r rune)
}
Ticker is a small consumer contract for the Spin function, capturing part of the Progress interface.
type VerboseProgress ¶
type VerboseProgress struct {
// contains filtered or unexported fields
}
VerboseProgress is an implementation of Progress that treats Step and Write more or less the same: it simply pipes all output to the provided Writer. No spinners are used.
func NewVerboseProgress ¶
func NewVerboseProgress(output io.Writer) *VerboseProgress
NewVerboseProgress returns a VerboseProgress outputting to the writer.
func (*VerboseProgress) Done ¶
func (p *VerboseProgress) Done()
Done implements the Progress interface. It's a no-op.
func (*VerboseProgress) Fail ¶
func (p *VerboseProgress) Fail()
Fail implements the Progress interface. It's a no-op.
func (*VerboseProgress) Step ¶
func (p *VerboseProgress) Step(msg string)
Step implements the Progress interface.
func (*VerboseProgress) Tick ¶
func (p *VerboseProgress) Tick(r rune)
Tick implements the Progress interface. It's a no-op.