component

package
v0.0.0-...-10f57cc Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package component defines components that can be made use of in plugins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ask

func Ask(q *QuestionConfig, response interface{}) error

Ask asks a questions and lets the user select an option.

func Prompt

func Prompt(p *PromptConfig, response interface{}, opts ...PromptOpt) error

Prompt for input.

func ReadInput

func ReadInput(filePath string) ([]byte, error)

ReadInput reads from file or std input and return a byte array.

func Select

func Select(p *SelectConfig, response interface{}) error

Select an option.

Types

type OutputType

type OutputType string

OutputType defines the format of the output desired.

const (
	// TableOutputType specifies output should be in table format.
	TableOutputType OutputType = "table"
	// YAMLOutputType specifies output should be in yaml format.
	YAMLOutputType OutputType = "yaml"
	// JSONOutputType specifies output should be in json format.
	JSONOutputType OutputType = "json"
	// ListTableOutputType specified output should be in a list table format.
	ListTableOutputType OutputType = "listtable"
)

type OutputWriter

type OutputWriter interface {
	SetKeys(headerKeys ...string)
	AddRow(items ...interface{})
	Render()
}

OutputWriter is an interface for something that can write output.

func NewObjectWriter

func NewObjectWriter(output io.Writer, outputFormat string, data interface{}) OutputWriter

NewObjectWriter gets a new instance of our output writer.

func NewOutputWriter

func NewOutputWriter(output io.Writer, outputFormat string, headers ...string) OutputWriter

NewOutputWriter gets a new instance of our output writer.

type OutputWriterSpinner

type OutputWriterSpinner interface {
	OutputWriter
	RenderWithSpinner()
	StopSpinner()
}

OutputWriterSpinner is OutputWriter augmented with a spinner.

func NewOutputWriterWithSpinner

func NewOutputWriterWithSpinner(output io.Writer, outputFormat, spinnerText string, startSpinner bool, headers ...string) (OutputWriterSpinner, error)

NewOutputWriterWithSpinner returns implementation of OutputWriterSpinner.

type PromptConfig

type PromptConfig struct {
	// Message to display to user.
	Message string

	// Options for user to choose from
	Options []string

	// Default option.
	Default string

	// Sensitive information.
	Sensitive bool

	// Help for the prompt.
	Help string
}

PromptConfig is the configuration for a prompt.

func (*PromptConfig) Run

func (p *PromptConfig) Run(response interface{}, opts ...PromptOpt) error

Run the prompt.

type PromptOpt

type PromptOpt func(*PromptOptions) error

PromptOpt is an option for prompts

func WithStdio

func WithStdio(in terminal.FileReader, out terminal.FileWriter, err io.Writer) PromptOpt

WithStdio specifies the standard input, output and error. By default, these are os.Stdin, os.Stdout, and os.Stderr.

type PromptOptions

type PromptOptions struct {
	// Standard in/out/error
	Stdio terminal.Stdio
}

PromptOptions are options for prompting.

type QuestionConfig

type QuestionConfig struct {
	Message string
}

QuestionConfig stores config for prompting a CLI question.

func (*QuestionConfig) Run

func (q *QuestionConfig) Run(response interface{}) error

Run asks a question.

type SelectConfig

type SelectConfig struct {
	// Message to display to user.
	Message string

	// Default option.
	Default interface{}

	// Options to select frorm.
	Options []string

	// Sensitive information.
	Sensitive bool

	// Help for the prompt.
	Help string

	// PageSize defines how many options per page.
	PageSize int
}

SelectConfig is the configuration for a selection.

func (*SelectConfig) Run

func (p *SelectConfig) Run(response interface{}) error

Run the selection.

Jump to

Keyboard shortcuts

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