cliui

package
v2.10.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfirmYes = "yes"
	ConfirmNo  = "no"
)
View Source
const (
	ProvisioningStateQueued  = "Queued"
	ProvisioningStateRunning = "Running"
)

Variables

View Source
var (
	Green   = Color("#04B575")
	Red     = Color("#ED567A")
	Fuchsia = Color("#EE6FF8")
	Yellow  = Color("#ECFD65")
	Blue    = Color("#5000ff")
)
View Source
var Canceled = xerrors.New("canceled")

Functions

func Agent

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

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

func Bold added in v2.2.0

func Bold(s string) string

Bold returns a formatter that renders text in bold if the terminal supports it.

func BoldFmt added in v2.2.0

func BoldFmt() pretty.Formatter

BoldFmt returns a formatter that renders text in bold if the terminal supports it.

func Code added in v2.2.0

func Code(s string) string

Code formats code for display.

func Color added in v2.2.0

func Color(s string) termenv.Color

Color returns a color for the given string.

func DeprecationWarning added in v2.7.0

func DeprecationWarning(message string) serpent.MiddlewareFunc

func DisplayTable

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

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

Error writes a log to the writer provided.

func Errorf

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

Errorf writes a formatted log to the writer provided.

func ExternalAuth added in v2.2.1

func ExternalAuth(ctx context.Context, writer io.Writer, opts ExternalAuthOptions) error

func Field added in v2.2.0

func Field(s string) string

Field formats a field for display.

func Info

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

Info writes a log to the writer provided.

func Infof

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

Infof writes a formatted log to the writer provided.

func Keyword added in v2.2.0

func Keyword(s string) string

Keyword formats a keyword for display.

func MultiSelect

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

func PeerDiagnostics added in v2.9.0

func PeerDiagnostics(w io.Writer, d tailnet.PeerDiagnostics)

func Placeholder added in v2.2.0

func Placeholder(s string) string

Placeholder formats a placeholder for display.

func Prompt

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

Prompt asks the user for input.

func ProvisionerJob

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

ProvisionerJob renders a provisioner job with interactive cancellation.

func RichParameter

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

func RichSelect

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

func Select

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

Select displays a list of user options.

func SkipPromptOption

func SkipPromptOption() serpent.Option

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

func Table

func Table() table.Writer

Table creates a new table with standardized styles.

func Timestamp added in v2.2.0

func Timestamp(t time.Time) string

Timestamp formats a timestamp for display.

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

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

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 │ └────────────────────────────────────────────────────────────────────────────┘

func Wrap added in v2.2.0

func Wrap(s string) string

Wrap prevents the text from overflowing the terminal.

Types

type AgentOptions

type AgentOptions struct {
	FetchInterval time.Duration
	Fetch         func(ctx context.Context, agentID uuid.UUID) (codersdk.WorkspaceAgent, error)
	FetchLogs     func(ctx context.Context, agentID uuid.UUID, after int64, follow bool) (<-chan []codersdk.WorkspaceAgentLog, io.Closer, error)
	Wait          bool // If true, wait for the agent to be ready (startup script).
}

type DataChangeFormat

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

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

ChangeFormatterData allows manipulating the data passed to an output format.

func (*DataChangeFormat) AttachOptions

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

func (*DataChangeFormat) Format

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

func (*DataChangeFormat) ID

func (d *DataChangeFormat) ID() string

type ExternalAuthOptions added in v2.2.1

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

type OutputFormat

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

func JSONFormat

func JSONFormat() OutputFormat

JSONFormat creates a JSON formatter.

func TableFormat

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

func TextFormat() OutputFormat

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

type OutputFormatter

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

func NewOutputFormatter

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

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

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

func (*OutputFormatter) Format

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

type ProvisionerJobError struct {
	Message string
	Code    codersdk.JobErrorCode
}

func (*ProvisionerJobError) Error

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

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 Styles

type Styles struct {
	Code,
	DateTimeStamp,
	Error,
	Field,
	Keyword,
	Placeholder,
	Prompt,
	FocusedPrompt,
	Fuchsia,
	Warn,
	Wrap pretty.Style
}
var DefaultStyles Styles

DefaultStyles compose visual elements of the UI.

type WorkspaceFilter added in v2.4.0

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

WorkspaceFilter wraps codersdk.WorkspaceFilter and allows easy integration to a CLI command. Example usage:

func (r *RootCmd) MyCmd() *serpent.Command {
  var (
    filter cliui.WorkspaceFilter
    ...
  )
  cmd := &serpent.Command{
    ...
  }
  filter.AttachOptions(&cmd.Options)
  ...
  return cmd
}

The above will add the following flags to the command: --all --search

func (*WorkspaceFilter) AttachOptions added in v2.4.0

func (w *WorkspaceFilter) AttachOptions(opts *serpent.OptionSet)

func (*WorkspaceFilter) Filter added in v2.4.0

type WorkspaceResourcesOptions

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