cli

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: 179 Imported by: 0

Documentation

Index

Constants

This section is empty.

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) (sqlDB *sql.DB, err error)

func CurrentOrganization

func CurrentOrganization(r *RootCmd, inv *serpent.Invocation, client *codersdk.Client) (codersdk.Organization, error)

CurrentOrganization returns the currently active organization for the authenticated user.

func DiscoverVarsFiles added in v2.7.0

func DiscoverVarsFiles(workDir string) ([]string, error)

*

  • DiscoverVarsFiles function loads vars files in a predefined order:
  • 1. terraform.tfvars
  • 2. terraform.tfvars.json
  • 3. *.auto.tfvars
  • 4. *.auto.tfvars.json

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 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 ParseUserVariableValues added in v2.6.0

func ParseUserVariableValues(varsFiles []string, variablesFile string, commandLineVariables []string) ([]codersdk.VariableValue, 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 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 ParameterResolver

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

func (*ParameterResolver) Resolve

func (*ParameterResolver) WithBuildOptions

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

func (*ParameterResolver) WithLastBuildParameters

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

func (*ParameterResolver) WithPromptBuildOptions

func (pr *ParameterResolver) WithPromptBuildOptions(promptBuildOptions 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) 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) 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 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