cmdutil

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitFailure   = 1
	ExitCancelled = 2
	ExitTimeout   = 124
)

Variables

This section is empty.

Functions

func AddJSONFieldsFlag

func AddJSONFieldsFlag(cmd *cobra.Command, target *string)

AddJSONFieldsFlag adds a --json flag that accepts optional field specification

func AddListFlags

func AddListFlags(cmd *cobra.Command, flags *ListFlags, defaultLimit int)

AddListFlags registers --limit, --json, --plain, and --no-header flags on a command.

func AddPlainFlags added in v0.8.3

func AddPlainFlags(cmd *cobra.Command, flags *ListFlags)

AddPlainFlags registers --plain and --no-header flags on a command. Use this for list commands that already register --json separately.

func AddViewFlags

func AddViewFlags(cmd *cobra.Command, opts *ViewOptions)

AddViewFlags adds --json and --web flags to a command.

func BuildResultError

func BuildResultError(p *output.Printer, client api.ClientInterface, build *api.Build, showDetails bool) error

BuildResultError prints the final build result and returns an appropriate exit error. Used by both the standard watch and TUI watch paths.

func FormatAgentStatus

func FormatAgentStatus(a api.Agent) string

FormatAgentStatus returns a formatted status string for an agent.

func NotAuthenticatedError

func NotAuthenticatedError(serverURL string, keyringErr error) *tcerrors.UserError

NotAuthenticatedError returns a not-authenticated error with a hint that covers all authentication methods: environment variables, interactive login, and guest access.

func ParseID

func ParseID(s string, entity string) (int, error)

ParseID converts a string argument to an integer ID.

func PrintFailureSummary

func PrintFailureSummary(p *output.Printer, client api.ClientInterface, buildID, buildNumber, webURL, statusText string)

func ProbeGuestAccess

func ProbeGuestAccess(serverURL string) bool

ProbeGuestAccess checks whether the server at serverURL supports guest access.

func ResolveAgent

func ResolveAgent(client api.ClientInterface, nameOrID string) (*api.Agent, error)

ResolveAgent resolves an agent name or ID to an Agent object.

func ResolveAgentID

func ResolveAgentID(client api.ClientInterface, nameOrID string) (int, string, error)

ResolveAgentID resolves an agent name or ID to a numeric agent ID and name.

func RunList

func RunList(
	f *Factory,
	cmd *cobra.Command,
	flags *ListFlags,
	fieldSpec *api.FieldSpec,
	fetch func(client api.ClientInterface, fields []string) (*ListResult, error),
) error

RunList handles the shared boilerplate for list commands: limit validation, JSON field parsing, client creation, fetch, and output.

func SubcommandRequired

func SubcommandRequired(cmd *cobra.Command, args []string) error

SubcommandRequired is a RunE function for parent commands that require a subcommand. It returns an error when no valid subcommand is provided.

func ValidateLimit

func ValidateLimit(limit int) error

ValidateLimit returns an error if limit is not positive.

Types

type ExitError

type ExitError struct {
	Code int
}

ExitError is returned by commands that need a specific exit code.

func (*ExitError) Error

func (e *ExitError) Error() string

type Factory

type Factory struct {
	// Global flags — set once by root command, read by subcommands.
	NoColor bool
	Quiet   bool
	Verbose bool
	NoInput bool

	// IOStreams provides standard I/O handles. Override in tests to capture output.
	IOStreams *IOStreams

	// Printer writes formatted output. Prefer this over the output package
	// free functions — it uses the Factory's IOStreams and respects Quiet/Verbose
	// without relying on package globals.
	Printer *output.Printer

	// ClientFunc returns an API client. Override in tests to inject mocks.
	ClientFunc func() (api.ClientInterface, error)

	// UpdateNotice is called after command execution to print update notices.
	UpdateNotice func()
}

Factory provides shared dependencies to all commands. Instead of reaching for package-level globals, commands receive a Factory and use its methods/fields to get clients, check flags, etc.

func NewFactory

func NewFactory() *Factory

NewFactory creates a Factory with production defaults.

func (*Factory) Client

func (f *Factory) Client() (api.ClientInterface, error)

Client returns an API client using the configured ClientFunc.

func (*Factory) InitOutput

func (f *Factory) InitOutput()

InitOutput configures output settings from Factory flags. Called once after flags are parsed (in PersistentPreRun).

func (*Factory) IsInteractive

func (f *Factory) IsInteractive() bool

IsInteractive returns true if the CLI can prompt the user.

func (*Factory) WarnInsecureHTTP

func (f *Factory) WarnInsecureHTTP(serverURL, credentialType string)

WarnInsecureHTTP prints a warning to stderr when connecting over plain HTTP.

type IOStreams

type IOStreams struct {
	In     io.Reader
	Out    io.Writer
	ErrOut io.Writer
}

IOStreams provides the standard streams for commands to read/write. Commands should use these instead of os.Stdin/os.Stdout/os.Stderr directly, enabling tests to capture output without redirecting globals.

type JSONFieldsResult

type JSONFieldsResult struct {
	Enabled bool
	Fields  []string
}

JSONFieldsResult represents the parsed result of --json flag

func ParseJSONFields

func ParseJSONFields(cmd *cobra.Command, flagValue string, spec *api.FieldSpec, out ...io.Writer) (JSONFieldsResult, bool, error)

ParseJSONFields parses the --json flag value, returns (result, showHelp, error).

type ListFlags

type ListFlags struct {
	Limit      int
	JSONFields string
	Plain      bool
	NoHeader   bool
}

ListFlags holds the common flags shared by all list commands.

type ListResult

type ListResult struct {
	JSON     any
	Table    ListTable
	EmptyMsg string
}

ListResult is returned by a list command's fetch function. Set either JSON (for JSON output) or Table (for table output).

type ListTable

type ListTable struct {
	Headers  []string
	Rows     [][]string
	FlexCols []int
}

ListTable holds the data needed to print a table.

type ViewOptions

type ViewOptions struct {
	JSON bool
	Web  bool
}

ViewOptions is shared by view commands that support JSON and web output.

Jump to

Keyboard shortcuts

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