component

package
v0.0.0-...-b25b198 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: Apache-2.0 Imports: 18 Imported by: 9

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 AskForConfirmation

func AskForConfirmation(message string) error

AskForConfirmation is used to prompt the user to confirm or deny a choice

func BeginsWith

func BeginsWith(s, prefix string) bool

func Bold

func Bold(s string) string

func IsTTYEnabled

func IsTTYEnabled() bool

func NewAurora

func NewAurora() auroraPackage.Aurora

func Prompt

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

Prompt for input, reads input value, without trimming any characters (may include leading/tailing spaces)

func ReadInput

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

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

func Rpad

func Rpad(s string, padding int) string

Rpad adds padding to the right of a string. from https://github.com/spf13/cobra/blob/993cc5372a05240dfd59e3ba952748b36b2cd117/cobra.go#L29

func Select

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

Select an option.

func TrimRightSpace

func TrimRightSpace(s string) string

func Underline

func Underline(s string) string

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
	Icons survey.IconSet
}

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