Movatterモバイル変換


[0]ホーム

URL:


cliui

package
v2.23.0Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2025 License:AGPL-3.0Imports:36Imported by:0

Details

Repository

github.com/coder/coder

Links

Documentation

Index

Constants

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

Variables

View Source
var ErrCanceled =xerrors.New("canceled")

Functions

funcAgent

func Agent(ctxcontext.Context, writerio.Writer, agentIDuuid.UUID, optsAgentOptions)error

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

funcBoldadded inv2.2.0

func Bold(sstring)string

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

funcBoldFmtadded inv2.2.0

func BoldFmt()pretty.Formatter

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

funcCodeadded inv2.2.0

func Code(sstring)string

Code formats code for display.

funcColoradded inv2.2.0

func Color(sstring)termenv.Color

Color returns a color for the given string.

funcDeprecationWarningadded inv2.7.0

func DeprecationWarning(messagestring)serpent.MiddlewareFunc

funcDisplayTable

func DisplayTable(outany, sortstring, filterColumns []string) (string,error)

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:""` tagcontaining 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 ismalformed or a field is marked as recursive but does not contain a struct ora pointer to a struct, this function will return an error (even with an emptyinput slice).

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

funcError

func Error(wtrio.Writer, headerstring, lines ...string)

Error writes a log to the writer provided.

funcErrorf

func Errorf(wtrio.Writer, fmtStrstring, args ...interface{})

Errorf writes a formatted log to the writer provided.

funcExternalAuthadded inv2.2.1

func ExternalAuth(ctxcontext.Context, writerio.Writer, optsExternalAuthOptions)error

funcFieldadded inv2.2.0

func Field(sstring)string

Field formats a field for display.

funcInfo

func Info(wtrio.Writer, headerstring, lines ...string)

Info writes a log to the writer provided.

funcInfof

func Infof(wtrio.Writer, fmtStrstring, args ...interface{})

Infof writes a formatted log to the writer provided.

funcKeywordadded inv2.2.0

func Keyword(sstring)string

Keyword formats a keyword for display.

funcMultiSelect

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

funcPeerDiagnosticsadded inv2.9.0

func PeerDiagnostics(wio.Writer, dtailnet.PeerDiagnostics)

funcPlaceholderadded inv2.2.0

func Placeholder(sstring)string

Placeholder formats a placeholder for display.

funcPrompt

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

Prompt asks the user for input.

funcProvisionerJob

func ProvisionerJob(ctxcontext.Context, wrio.Writer, optsProvisionerJobOptions)error

ProvisionerJob renders a provisioner job with interactive cancellation.

funcRichParameter

func RichParameter(inv *serpent.Invocation, templateVersionParametercodersdk.TemplateVersionParameter, defaultOverrides map[string]string) (string,error)

funcRichSelect

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

funcSelect

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

Select displays a list of user options.

funcSkipPromptOption

func SkipPromptOption()serpent.Option

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

funcTable

func Table()table.Writer

Table creates a new table with standardized styles.

funcTimestampadded inv2.2.0

func Timestamp(ttime.Time)string

Timestamp formats a timestamp for display.

funcValidateNotEmpty

func ValidateNotEmpty(sstring)error

ValidateNotEmpty is a helper function to disallow empty inputs!

funcWarn

func Warn(wtrio.Writer, headerstring, lines ...string)

Warn writes a log to the writer provided.

funcWarnf

func Warnf(wtrio.Writer, fmtStrstring, args ...interface{})

Warn writes a formatted log to the writer provided.

funcWorkspaceBuild

func WorkspaceBuild(ctxcontext.Context, writerio.Writer, client *codersdk.Client, builduuid.UUID)error

funcWorkspaceResources

func WorkspaceResources(writerio.Writer, resources []codersdk.WorkspaceResource, optionsWorkspaceResourcesOptions)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 │└────────────────────────────────────────────────────────────────────────────┘

funcWrapadded inv2.2.0

func Wrap(sstring)string

Wrap prevents the text from overflowing the terminal.

Types

typeAgentOptions

type AgentOptions struct {FetchIntervaltime.DurationFetch         func(ctxcontext.Context, agentIDuuid.UUID) (codersdk.WorkspaceAgent,error)FetchLogs     func(ctxcontext.Context, agentIDuuid.UUID, afterint64, followbool) (<-chan []codersdk.WorkspaceAgentLog,io.Closer,error)Waitbool// If true, wait for the agent to be ready (startup script).DocsURLstring}

typeConnDiagsadded inv2.15.0

type ConnDiags struct {ConnInfoworkspacesdk.AgentConnectionInfoPingP2PboolDisableDirectboolLocalNetInfo       *tailcfg.NetInfoLocalInterfaces    *healthsdk.InterfacesReportAgentNetcheck      *healthsdk.AgentNetcheckReportClientIPIsAWSboolAgentIPIsAWSboolVerboseboolTroubleshootingURLstring}

func (ConnDiags)Writeadded inv2.15.0

func (dConnDiags) Write(wio.Writer)

typeDataChangeFormat

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 bepassed to the output format.For example, you may want to pass something different to the text formatterthan what you pass to the json formatter.

funcChangeFormatterData

func ChangeFormatterData(formatOutputFormat, change func(dataany) (any,error)) *DataChangeFormat

ChangeFormatterData allows manipulating the data passed to an outputformat.

func (*DataChangeFormat)AttachOptions

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

func (*DataChangeFormat)Format

func (d *DataChangeFormat) Format(ctxcontext.Context, dataany) (string,error)

func (*DataChangeFormat)ID

func (d *DataChangeFormat) ID()string

typeExternalAuthOptionsadded inv2.2.1

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

typeMultiSelectOptionsadded inv2.13.0

type MultiSelectOptions struct {MessagestringOptions           []stringDefaults          []stringEnableCustomInputbool}

typeOutputFormat

type OutputFormat interface {ID()stringAttachOptions(opts *serpent.OptionSet)Format(ctxcontext.Context, dataany) (string,error)}

funcJSONFormat

func JSONFormat()OutputFormat

JSONFormat creates a JSON formatter.

funcTableFormat

func TableFormat(outany, defaultColumns []string)OutputFormat

TableFormat creates a table formatter for the given output type. The outputtype 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. Ifnot specified, all columns are displayed by default.

funcTextFormat

func TextFormat()OutputFormat

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

typeOutputFormatter

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

funcNewOutputFormatter

func NewOutputFormatter(formats ...OutputFormat) *OutputFormatter

NewOutputFormatter creates a new OutputFormatter with the given formats. Thefirst 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 anyadditional flags required by the output formatters.

func (*OutputFormatter)Format

func (f *OutputFormatter) Format(ctxcontext.Context, dataany) (string,error)

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

func (*OutputFormatter)FormatIDadded inv2.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.

typePromptOptions

type PromptOptions struct {TextstringDefaultstring// When true, the input will be masked with asterisks.SecretboolIsConfirmboolValidate  func(string)error}

PromptOptions supply a set of options to the prompt.

typeProvisionerJobError

type ProvisionerJobError struct {MessagestringCodecodersdk.JobErrorCode}

func (*ProvisionerJobError)Error

func (err *ProvisionerJobError) Error()string

typeProvisionerJobOptions

type ProvisionerJobOptions struct {Fetch  func() (codersdk.ProvisionerJob,error)Cancel func()errorLogs   func() (<-chancodersdk.ProvisionerJobLog,io.Closer,error)FetchIntervaltime.Duration// Verbose determines whether debug and trace logs will be shown.Verbosebool// Silent determines whether log output will be shown unless there is an// error.Silentbool}

typeRichSelectOptions

type RichSelectOptions struct {Options    []codersdk.TemplateVersionParameterOptionDefaultstringSizeintHideSearchbool}

typeSelectOptions

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

typeStyles

type Styles struct {Code,DateTimeStamp,Error,Field,Hyperlink,Keyword,Placeholder,Prompt,FocusedPrompt,Fuchsia,Warn,Wrappretty.Style}
var DefaultStylesStyles

DefaultStyles compose visual elements of the UI.

typeTableSeparatoradded inv2.13.0

type TableSeparator struct{}

This type can be supplied as part of a slice to DisplayTableor to a `TableFormat` `Format` call to render a separator.Leading separators are not supported and trailing separatorsare ignored by the table formatter.e.g. `[]any{someRow, TableSeparator, someRow}`

typeWorkspaceFilteradded inv2.4.0

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

WorkspaceFilter wraps codersdk.WorkspaceFilterand 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)AttachOptionsadded inv2.4.0

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

func (*WorkspaceFilter)Filteradded inv2.4.0

typeWorkspaceResourcesOptions

type WorkspaceResourcesOptions struct {WorkspaceNamestringHideAgentStateboolHideAccessboolTitlestringServerVersionstringListeningPorts map[uuid.UUID]codersdk.WorkspaceAgentListeningPortsResponseDevcontainers  map[uuid.UUID]codersdk.WorkspaceAgentListContainersResponse}

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp