Documentation
ΒΆ
Index ΒΆ
- Constants
- Variables
- func Agent(ctx context.Context, writer io.Writer, agentID uuid.UUID, opts AgentOptions) error
- func Bold(s string) string
- func BoldFmt() pretty.Formatter
- func Code(s string) string
- func Color(s string) termenv.Color
- func DeprecationWarning(message string) serpent.MiddlewareFunc
- func DisplayTable(out any, sort string, filterColumns []string) (string, error)
- func Error(wtr io.Writer, header string, lines ...string)
- func Errorf(wtr io.Writer, fmtStr string, args ...interface{})
- func ExternalAuth(ctx context.Context, writer io.Writer, opts ExternalAuthOptions) error
- func Field(s string) string
- func Info(wtr io.Writer, header string, lines ...string)
- func Infof(wtr io.Writer, fmtStr string, args ...interface{})
- func Keyword(s string) string
- func MultiSelect(inv *serpent.Invocation, opts MultiSelectOptions) ([]string, error)
- func PeerDiagnostics(w io.Writer, d tailnet.PeerDiagnostics)
- func Placeholder(s string) string
- func Prompt(inv *serpent.Invocation, opts PromptOptions) (string, error)
- func ProvisionerJob(ctx context.Context, wr io.Writer, opts ProvisionerJobOptions) error
- func RichParameter(inv *serpent.Invocation, ...) (string, error)
- func RichSelect(inv *serpent.Invocation, richOptions RichSelectOptions) (*codersdk.TemplateVersionParameterOption, error)
- func Select(inv *serpent.Invocation, opts SelectOptions) (string, error)
- func SkipPromptOption() serpent.Option
- func Table() table.Writer
- func Timestamp(t time.Time) string
- func ValidateNotEmpty(s string) error
- func Warn(wtr io.Writer, header string, lines ...string)
- func Warnf(wtr io.Writer, fmtStr string, args ...interface{})
- func WorkspaceBuild(ctx context.Context, writer io.Writer, client *codersdk.Client, ...) error
- func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource, ...) error
- func Wrap(s string) string
- type AgentOptions
- type ConnDiags
- type DataChangeFormat
- type ExternalAuthOptions
- type MultiSelectOptions
- type OutputFormat
- type OutputFormatter
- type PromptOptions
- type ProvisionerJobError
- type ProvisionerJobOptions
- type RichSelectOptions
- type SelectOptions
- type Styles
- type TableSeparator
- type WorkspaceFilter
- type WorkspaceResourcesOptions
Constants ΒΆ
const ( ConfirmYes = "yes" ConfirmNo = "no" )
const ( ProvisioningStateQueued = "Queued" ProvisioningStateRunning = "Running" )
Variables ΒΆ
var ErrCanceled = xerrors.New("canceled")
Functions ΒΆ
func Bold ΒΆ added in v2.2.0
Bold returns a formatter that renders text in bold if the terminal supports it.
func BoldFmt ΒΆ added in v2.2.0
BoldFmt returns a formatter that renders text in bold if the terminal supports it.
func DeprecationWarning ΒΆ added in v2.7.0
func DeprecationWarning(message string) serpent.MiddlewareFunc
func DisplayTable ΒΆ
DisplayTable renders a table as a string. The input argument can be:
- a struct slice.
- an interface slice, where the first element is a struct, and all other elements are of the same type, or a TableSeparator.
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 ExternalAuth ΒΆ added in v2.2.1
func MultiSelect ΒΆ
func MultiSelect(inv *serpent.Invocation, opts MultiSelectOptions) ([]string, error)
func PeerDiagnostics ΒΆ added in v2.9.0
func PeerDiagnostics(w io.Writer, d tailnet.PeerDiagnostics)
func Placeholder ΒΆ added in v2.2.0
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 ΒΆ
ProvisionerJob renders a provisioner job with interactive cancellation.
func RichParameter ΒΆ
func RichParameter(inv *serpent.Invocation, templateVersionParameter codersdk.TemplateVersionParameter, defaultOverrides map[string]string) (string, error)
func RichSelect ΒΆ
func RichSelect(inv *serpent.Invocation, richOptions RichSelectOptions) (*codersdk.TemplateVersionParameterOption, error)
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 ΒΆ
SkipPromptOption adds a "--yes/-y" flag to the cmd that can be used to skip prompts.
func ValidateNotEmpty ΒΆ
ValidateNotEmpty is a helper function to disallow empty inputs!
func WorkspaceBuild ΒΆ
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 β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
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). DocsURL string }
type ConnDiags ΒΆ added in v2.15.0
type ConnDiags struct { ConnInfo workspacesdk.AgentConnectionInfo PingP2P bool DisableDirect bool LocalNetInfo *tailcfg.NetInfo LocalInterfaces *healthsdk.InterfacesReport AgentNetcheck *healthsdk.AgentNetcheckReport ClientIPIsAWS bool AgentIPIsAWS bool Verbose bool TroubleshootingURL string }
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) ID ΒΆ
func (d *DataChangeFormat) ID() string
type ExternalAuthOptions ΒΆ added in v2.2.1
type MultiSelectOptions ΒΆ added in v2.13.0
type OutputFormat ΒΆ
type OutputFormat interface { ID() string AttachOptions(opts *serpent.OptionSet) Format(ctx context.Context, data any) (string, error) }
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 ΒΆ
Format formats the given data using the format specified by the --output flag. If the flag is not set, the default format is used.
func (*OutputFormatter) FormatID ΒΆ added in v2.20.0
func (f *OutputFormatter) FormatID() string
FormatID will return the ID of the format selected by `--output`. If no flag is present, it returns the 'default' formatter.
type PromptOptions ΒΆ
type PromptOptions struct { Text string Default string // When true, the input will be masked with asterisks. 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 Styles ΒΆ
type Styles struct { Code, DateTimeStamp, Error, Field, Hyperlink, Keyword, Placeholder, Prompt, FocusedPrompt, Fuchsia, Warn, Wrap pretty.Style }
var DefaultStyles Styles
DefaultStyles compose visual elements of the UI.
type TableSeparator ΒΆ added in v2.13.0
type TableSeparator struct{}
This type can be supplied as part of a slice to DisplayTable or to a `TableFormat` `Format` call to render a separator. Leading separators are not supported and trailing separators are ignored by the table formatter. e.g. `[]any{someRow, TableSeparator, someRow}`
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
func (w *WorkspaceFilter) Filter() codersdk.WorkspaceFilter