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 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