cliui

package
v0.23.5 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: AGPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfirmYes = "yes"
	ConfirmNo  = "no"
)

Variables

View Source
var (
	AgentStartError   = xerrors.New("agent startup exited with non-zero exit status")
	AgentShuttingDown = xerrors.New("agent is shutting down")
)
View Source
var (
	Canceled = xerrors.New("canceled")
)
View Source
var Styles = struct {
	Bold,
	Checkmark,
	Code,
	Crossmark,
	DateTimeStamp,
	Error,
	Field,
	Keyword,
	Paragraph,
	Placeholder,
	Prompt,
	FocusedPrompt,
	Fuchsia,
	Logo,
	Warn,
	Wrap lipgloss.Style
}{
	Bold:          lipgloss.NewStyle().Bold(true),
	Checkmark:     defaultStyles.Checkmark,
	Code:          defaultStyles.Code,
	Crossmark:     defaultStyles.Error.Copy().SetString("✘"),
	DateTimeStamp: defaultStyles.LabelDim,
	Error:         defaultStyles.Error,
	Field:         defaultStyles.Code.Copy().Foreground(lipgloss.AdaptiveColor{Light: "#000000", Dark: "#FFFFFF"}),
	Keyword:       defaultStyles.Keyword,
	Paragraph:     defaultStyles.Paragraph,
	Placeholder:   lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#585858", Dark: "#4d46b3"}),
	Prompt:        defaultStyles.Prompt.Copy().Foreground(lipgloss.AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"}),
	FocusedPrompt: defaultStyles.FocusedPrompt.Copy().Foreground(lipgloss.Color("#651fff")),
	Fuchsia:       defaultStyles.SelectedMenuItem.Copy(),
	Logo:          defaultStyles.Logo.Copy().SetString("Coder"),
	Warn: lipgloss.NewStyle().Foreground(
		lipgloss.AdaptiveColor{Light: "#04B575", Dark: "#ECFD65"},
	),
	Wrap: lipgloss.NewStyle().Width(80),
}

Styles compose visual elements of the UI!

Functions

func Agent

func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error

Agent displays a spinning indicator that waits for a workspace agent to connect.

func DisplayTable added in v0.8.6

func DisplayTable(out any, sort string, filterColumns []string) (string, error)

DisplayTable renders a table as a string. The input argument must be a slice of structs. At least one field in the struct must have a `table:""` tag containing the name of the column in the outputted table.

If `sort` is not specified, the field with the `table:"$NAME,default_sort"` tag will be used to sort. An error will be returned if no field has this tag.

Nested structs are processed if the field has the `table:"$NAME,recursive"` tag and their fields will be named as `$PARENT_NAME $NAME`. If the tag is malformed or a field is marked as recursive but does not contain a struct or a pointer to a struct, this function will return an error (even with an empty input slice).

If sort is empty, the input order will be used. If filterColumns is empty or nil, all available columns are included.

func Error added in v0.21.0

func Error(wtr io.Writer, header string, lines ...string)

Error writes a log to the writer provided.

func Errorf added in v0.21.0

func Errorf(wtr io.Writer, fmtStr string, args ...interface{})

Errorf writes a formatted log to the writer provided.

func GitAuth added in v0.18.0

func GitAuth(ctx context.Context, writer io.Writer, opts GitAuthOptions) error

func Info added in v0.21.0

func Info(wtr io.Writer, header string, lines ...string)

Info writes a log to the writer provided.

func Infof added in v0.21.0

func Infof(wtr io.Writer, fmtStr string, args ...interface{})

Infof writes a formatted log to the writer provided.

func MultiSelect added in v0.20.0

func MultiSelect(inv *clibase.Invocation, items []string) ([]string, error)

func ParameterSchema

func ParameterSchema(inv *clibase.Invocation, parameterSchema codersdk.ParameterSchema) (string, error)

func Prompt

func Prompt(inv *clibase.Invocation, opts PromptOptions) (string, error)

Prompt asks the user for input.

func ProvisionerJob

func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOptions) error

ProvisionerJob renders a provisioner job with interactive cancellation.

func RichParameter added in v0.15.2

func RichParameter(inv *clibase.Invocation, templateVersionParameter codersdk.TemplateVersionParameter) (string, error)

func RichSelect added in v0.15.3

RichSelect displays a list of user options including name and description.

func Select

func Select(inv *clibase.Invocation, opts SelectOptions) (string, error)

Select displays a list of user options.

func SkipPromptOption added in v0.21.0

func SkipPromptOption() clibase.Option

SkipPromptOption adds a "--yes/-y" flag to the cmd that can be used to skip prompts.

func Table added in v0.5.6

func Table() table.Writer

Table creates a new table with standardized styles.

func ValidateNotEmpty

func ValidateNotEmpty(s string) error

ValidateNotEmpty is a helper function to disallow empty inputs!

func Warn

func Warn(wtr io.Writer, header string, lines ...string)

Warn writes a log to the writer provided.

func Warnf added in v0.21.0

func Warnf(wtr io.Writer, fmtStr string, args ...interface{})

Warn writes a formatted log to the writer provided.

func WorkspaceBuild

func WorkspaceBuild(ctx context.Context, writer io.Writer, client *codersdk.Client, build uuid.UUID) error

func WorkspaceResources added in v0.4.1

func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource, options WorkspaceResourcesOptions) error

WorkspaceResources displays the connection status and tree-view of provided resources. ┌────────────────────────────────────────────────────────────────────────────┐ │ RESOURCE STATUS ACCESS │ ├────────────────────────────────────────────────────────────────────────────┤ │ google_compute_disk.root │ ├────────────────────────────────────────────────────────────────────────────┤ │ google_compute_instance.dev │ │ └─ dev (linux, amd64) ⦾ connecting [10s] coder ssh dev.dev │ ├────────────────────────────────────────────────────────────────────────────┤ │ kubernetes_pod.dev │ │ ├─ go (linux, amd64) ⦿ connected coder ssh dev.go │ │ └─ postgres (linux, amd64) ⦾ disconnected [4s] coder ssh dev.postgres │ └────────────────────────────────────────────────────────────────────────────┘

Types

type AgentOptions

type AgentOptions struct {
	WorkspaceName string
	Fetch         func(context.Context) (codersdk.WorkspaceAgent, error)
	FetchInterval time.Duration
	WarnInterval  time.Duration
	NoWait        bool // If true, don't wait for the agent to be ready.
}

type DataChangeFormat added in v0.23.0

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

DataChangeFormat allows manipulating the data passed to an output format. This is because sometimes the data needs to be manipulated before it can be passed to the output format. For example, you may want to pass something different to the text formatter than what you pass to the json formatter.

func ChangeFormatterData added in v0.23.0

func ChangeFormatterData(format OutputFormat, change func(data any) (any, error)) *DataChangeFormat

ChangeFormatterData allows manipulating the data passed to an output format.

func (*DataChangeFormat) AttachOptions added in v0.23.0

func (d *DataChangeFormat) AttachOptions(opts *clibase.OptionSet)

func (*DataChangeFormat) Format added in v0.23.0

func (d *DataChangeFormat) Format(ctx context.Context, data any) (string, error)

func (*DataChangeFormat) ID added in v0.23.0

func (d *DataChangeFormat) ID() string

type GitAuthOptions added in v0.18.0

type GitAuthOptions struct {
	Fetch         func(context.Context) ([]codersdk.TemplateVersionGitAuth, error)
	FetchInterval time.Duration
}

type OutputFormat added in v0.17.1

type OutputFormat interface {
	ID() string
	AttachOptions(opts *clibase.OptionSet)
	Format(ctx context.Context, data any) (string, error)
}

func JSONFormat added in v0.17.1

func JSONFormat() OutputFormat

JSONFormat creates a JSON formatter.

func TableFormat added in v0.17.1

func TableFormat(out any, defaultColumns []string) OutputFormat

TableFormat creates a table formatter for the given output type. The output type should be specified as an empty slice of the desired type.

E.g.: TableFormat([]MyType{}, []string{"foo", "bar"})

defaultColumns is optional and specifies the default columns to display. If not specified, all columns are displayed by default.

func TextFormat added in v0.22.0

func TextFormat() OutputFormat

TextFormat is a formatter that just outputs unstructured text. It uses fmt.Sprintf under the hood.

type OutputFormatter added in v0.17.1

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

func NewOutputFormatter added in v0.17.1

func NewOutputFormatter(formats ...OutputFormat) *OutputFormatter

NewOutputFormatter creates a new OutputFormatter with the given formats. The first format is the default format. At least two formats must be provided.

func (*OutputFormatter) AttachOptions added in v0.21.0

func (f *OutputFormatter) AttachOptions(opts *clibase.OptionSet)

AttachOptions attaches the --output flag to the given command, and any additional flags required by the output formatters.

func (*OutputFormatter) Format added in v0.17.1

func (f *OutputFormatter) Format(ctx context.Context, data any) (string, error)

Format formats the given data using the format specified by the --output flag. If the flag is not set, the default format is used.

type PromptOptions

type PromptOptions struct {
	Text      string
	Default   string
	Secret    bool
	IsConfirm bool
	Validate  func(string) error
}

PromptOptions supply a set of options to the prompt.

type ProvisionerJobError added in v0.19.0

type ProvisionerJobError struct {
	Message string
	Code    codersdk.JobErrorCode
}

func (*ProvisionerJobError) Error added in v0.19.0

func (err *ProvisionerJobError) Error() string

type ProvisionerJobOptions

type ProvisionerJobOptions struct {
	Fetch  func() (codersdk.ProvisionerJob, error)
	Cancel func() error
	Logs   func() (<-chan codersdk.ProvisionerJobLog, io.Closer, error)

	FetchInterval time.Duration
	// Verbose determines whether debug and trace logs will be shown.
	Verbose bool
	// Silent determines whether log output will be shown unless there is an
	// error.
	Silent bool
}

type RichSelectOptions added in v0.15.3

type RichSelectOptions struct {
	Options    []codersdk.TemplateVersionParameterOption
	Default    string
	Size       int
	HideSearch bool
}

type SelectOptions

type SelectOptions struct {
	Options []string
	// Default will be highlighted first if it's a valid option.
	Default    string
	Size       int
	HideSearch bool
}

type WorkspaceResourcesOptions added in v0.4.1

type WorkspaceResourcesOptions struct {
	WorkspaceName  string
	HideAgentState bool
	HideAccess     bool
	Title          string
	ServerVersion  string
}

Jump to

Keyboard shortcuts

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