Thanks to visit codestin.com
Credit goes to pkg.go.dev

cli

package
v2.21.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: AGPL-3.0 Imports: 188 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Client ID for https://github.com/apps/coder
	GithubOAuth2DefaultProviderClientID      = "Iv1.6a2b4b4aec4f4fe7"
	GithubOAuth2DefaultProviderAllowEveryone = true
	GithubOAuth2DefaultProviderDeviceFlow    = true
)

Variables

View Source
var (
	Caret = pretty.Sprint(cliui.DefaultStyles.Prompt, "")
)
View Source
var InterruptSignals = []os.Signal{
	os.Interrupt,
}

InterruptSignals is the list of signals that are used for handling immediate shutdown behavior.

StopSignals is the list of signals that are used for handling shutdown behavior.

View Source
var StopSignalsNoInterrupt = []os.Signal{
	syscall.SIGTERM,
	syscall.SIGHUP,
}

StopSignals is the list of signals that are used for handling graceful shutdown behavior.

Functions

func ConfigureHTTPClient

func ConfigureHTTPClient(ctx context.Context, clientCertFile, clientKeyFile string, tlsClientCAFile string) (context.Context, *http.Client, error)

func ConfigureTraceProvider

func ConfigureTraceProvider(
	ctx context.Context,
	logger slog.Logger,
	cfg *codersdk.DeploymentValues,
) (trace.TracerProvider, string, func(context.Context) error)

func ConnectToPostgres added in v2.2.0

func ConnectToPostgres(ctx context.Context, logger slog.Logger, driver string, dbURL string, migrate func(db *sql.DB) error) (*sql.DB, error)

ConnectToPostgres takes in the migration command to run on the database once it connects. To avoid running migrations, pass in `nil` or a no-op function. Regardless of the passed in migration function, if the database is not fully migrated, an error will be returned. This can happen if the database is on a future or past migration version.

If no error is returned, the database is fully migrated and up to date.

func DumpHandler

func DumpHandler(ctx context.Context, name string)

DumpHandler provides a custom SIGQUIT and SIGTRAP handler that dumps the stacktrace of all goroutines to stderr and a well-known file in the home directory. This is useful for debugging deadlock issues that may occur in production in workspaces, since the default Go runtime will only dump to stderr (which is often difficult/impossible to read in a workspace).

SIGQUITs will still cause the program to exit (similarly to the default Go runtime behavior).

A SIGQUIT handler will not be registered if GOTRACEBACK=crash.

On Windows this immediately returns.

func ExitError added in v2.5.0

func ExitError(code int, err error) error

ExitError returns an error that will cause the CLI to exit with the given exit code. If err is non-nil, it will be wrapped by the returned error.

func FormatExamples added in v2.12.0

func FormatExamples(examples ...Example) string

FormatExamples formats the examples as width wrapped bulletpoint descriptions with the command underneath.

func IsLocalURL

func IsLocalURL(ctx context.Context, u *url.URL) (bool, error)

isLocalURL returns true if the hostname of the provided URL appears to resolve to a loopback address.

func IsLocalhost

func IsLocalhost(host string) bool

IsLocalhost returns true if the host points to the local machine. Intended to be called with `u.Hostname()`.

func ParseProvisionerTags

func ParseProvisionerTags(rawTags []string) (map[string]string, error)

func PrintDeprecatedOptions

func PrintDeprecatedOptions() serpent.MiddlewareFunc

printDeprecatedOptions loops through all command options, and prints a warning for usage of deprecated options.

func PrintLogo(inv *serpent.Invocation, daemonTitle string)

nolint: revive

func ReadExternalAuthProvidersFromEnv added in v2.2.1

func ReadExternalAuthProvidersFromEnv(environ []string) ([]codersdk.ExternalAuthConfig, error)

ReadExternalAuthProvidersFromEnv is provided for compatibility purposes with the viper CLI.

func ServeHandler

func ServeHandler(ctx context.Context, logger slog.Logger, handler http.Handler, addr, name string) (closeFunc func())

func SlimUnsupported added in v2.1.5

func SlimUnsupported(w io.Writer, cmd string)

func WriteConfigMW

func WriteConfigMW(cfg *codersdk.DeploymentValues) serpent.MiddlewareFunc

writeConfigMW will prevent the main command from running if the write-config flag is set. Instead, it will marshal the command options to YAML and write them to stdout.

Types

type ClaudeConfig added in v2.21.0

type ClaudeConfig struct {
	ConfigPath       string
	ProjectDirectory string
	APIKey           string
	AllowedTools     []string
	MCPServers       map[string]ClaudeConfigMCP
}

type ClaudeConfigMCP added in v2.21.0

type ClaudeConfigMCP struct {
	Command string            `json:"command"`
	Args    []string          `json:"args"`
	Env     map[string]string `json:"env"`
}

type Example added in v2.12.0

type Example struct {
	Description string
	Command     string
}

Example represents a standard example for command usage, to be used with FormatExamples.

type HTTPServers

type HTTPServers struct {
	HTTPUrl      *url.URL
	HTTPListener net.Listener

	// TLS
	TLSUrl      *url.URL
	TLSListener net.Listener
	TLSConfig   *tls.Config
}

func ConfigureHTTPServers

func ConfigureHTTPServers(logger slog.Logger, inv *serpent.Invocation, cfg *codersdk.DeploymentValues) (_ *HTTPServers, err error)

func (*HTTPServers) Close

func (s *HTTPServers) Close()

func (*HTTPServers) Serve

func (s *HTTPServers) Serve(srv *http.Server) error

Serve acts just like http.Serve. It is a blocking call until the server is closed, and an error is returned if any underlying Serve call fails.

type OrganizationContext added in v2.14.0

type OrganizationContext struct {
	// FlagSelect is the value passed in via the --org flag
	FlagSelect string
}

func NewOrganizationContext added in v2.14.0

func NewOrganizationContext() *OrganizationContext

func (*OrganizationContext) AttachOptions added in v2.14.0

func (o *OrganizationContext) AttachOptions(cmd *serpent.Command)

func (*OrganizationContext) Selected added in v2.14.0

func (*OrganizationContext) ValueSource added in v2.14.0

type ParameterResolver

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

func (*ParameterResolver) Resolve

func (*ParameterResolver) WithEphemeralParameters added in v2.17.0

func (pr *ParameterResolver) WithEphemeralParameters(params []codersdk.WorkspaceBuildParameter) *ParameterResolver

func (*ParameterResolver) WithLastBuildParameters

func (pr *ParameterResolver) WithLastBuildParameters(params []codersdk.WorkspaceBuildParameter) *ParameterResolver

func (*ParameterResolver) WithPromptEphemeralParameters added in v2.17.0

func (pr *ParameterResolver) WithPromptEphemeralParameters(promptEphemeralParameters bool) *ParameterResolver

func (*ParameterResolver) WithPromptRichParameters

func (pr *ParameterResolver) WithPromptRichParameters(promptRichParameters bool) *ParameterResolver

func (*ParameterResolver) WithRichParameters

func (pr *ParameterResolver) WithRichParameters(params []codersdk.WorkspaceBuildParameter) *ParameterResolver

func (*ParameterResolver) WithRichParametersDefaults added in v2.11.0

func (pr *ParameterResolver) WithRichParametersDefaults(params []codersdk.WorkspaceBuildParameter) *ParameterResolver

func (*ParameterResolver) WithRichParametersFile

func (pr *ParameterResolver) WithRichParametersFile(fileMap map[string]string) *ParameterResolver

func (*ParameterResolver) WithSourceWorkspaceParameters added in v2.4.0

func (pr *ParameterResolver) WithSourceWorkspaceParameters(params []codersdk.WorkspaceBuildParameter) *ParameterResolver

type PrettyErrorFormatter added in v2.10.0

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

func NewPrettyErrorFormatter added in v2.10.0

func NewPrettyErrorFormatter(w io.Writer, verbose bool) *PrettyErrorFormatter

NewPrettyErrorFormatter creates a new PrettyErrorFormatter.

func (*PrettyErrorFormatter) Format added in v2.10.0

func (p *PrettyErrorFormatter) Format(err error)

Format formats the error to the writer in PrettyErrorFormatter. This error should be human readable.

type RootCmd

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

RootCmd contains parameters and helpers useful to all commands.

func (*RootCmd) AGPL

func (r *RootCmd) AGPL() []*serpent.Command

func (*RootCmd) Command

func (r *RootCmd) Command(subcommands []*serpent.Command) (*serpent.Command, error)

func (*RootCmd) CoreSubcommands added in v2.10.0

func (r *RootCmd) CoreSubcommands() []*serpent.Command

func (*RootCmd) HeaderTransport added in v2.5.0

func (r *RootCmd) HeaderTransport(ctx context.Context, serverURL *url.URL) (*codersdk.HeaderTransport, error)

HeaderTransport creates a new transport that executes `--header-command` if it is set to add headers for all outbound requests.

func (*RootCmd) InitClient

func (r *RootCmd) InitClient(client *codersdk.Client) serpent.MiddlewareFunc

InitClient authenticates the client with files from disk and injects header middlewares for telemetry, authentication, and version checks.

func (*RootCmd) Provisioners added in v2.19.0

func (r *RootCmd) Provisioners() *serpent.Command

func (*RootCmd) RunWithSubcommands added in v2.10.0

func (r *RootCmd) RunWithSubcommands(subcommands []*serpent.Command)

RunWithSubcommands runs the root command with the given subcommands. It is abstracted to enable the Enterprise code to add commands.

func (*RootCmd) Server

func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Closer, error)) *serpent.Command

func (*RootCmd) Verbosef added in v2.1.4

func (r *RootCmd) Verbosef(inv *serpent.Invocation, fmtStr string, args ...interface{})

Verbosef logs a message if verbose mode is enabled.

type SpeedtestResult added in v2.13.0

type SpeedtestResult struct {
	Overall   SpeedtestResultInterval   `json:"overall"`
	Intervals []SpeedtestResultInterval `json:"intervals"`
}

type SpeedtestResultInterval added in v2.13.0

type SpeedtestResultInterval struct {
	StartTimeSeconds float64 `json:"start_time_seconds"`
	EndTimeSeconds   float64 `json:"end_time_seconds"`
	ThroughputMbits  float64 `json:"throughput_mbits"`
}

type WorkspaceCLIAction

type WorkspaceCLIAction int
const (
	WorkspaceCreate WorkspaceCLIAction = iota
	WorkspaceStart
	WorkspaceUpdate
	WorkspaceRestart
)

Directories

Path Synopsis
Package clilog provides a fluent API for configuring structured logging.
Package clilog provides a fluent API for configuring structured logging.

Jump to

Keyboard shortcuts

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