cmdutil

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultBitriseConfigFileName ...
	DefaultBitriseConfigFileName = "bitrise.yml"
	// DefaultSecretsFileName ...
	DefaultSecretsFileName = ".bitrise.secrets.yml"
	// OutputFormatKey ...
	OutputFormatKey = "output-format"
)
View Source
const (
	CollectionPathEnvKey = "STEPMAN_COLLECTION"
	CIKey                = "ci"
	PRKey                = "pr"
	DebugModeKey         = "debug"

	CollectionKey = "collection"

	InventoryBase64Key = "inventory-base64"

	ConfigBase64Key = "config-base64"

	JSONParamsKey       = "json-params"
	JSONParamsBase64Key = "json-params-base64"
	WorkflowKey         = "workflow"
	PatternKey          = "pattern"
	PushBranchKey       = "push-branch"
	PRSourceBranchKey   = "pr-source-branch"
	PRTargetBranchKey   = "pr-target-branch"
	PRReadyStateKey     = "pr-ready-state"
	ConfigKey           = "config"
	InventoryKey        = "inventory"
	// FormatKey selects the output format. It takes the -f shorthand only on
	// commands that have no --file flag: where both exist (yml update/validate,
	// rde template create/update), -f binds to --file and --format has none.
	FormatKey = "format"

	TagKey    = "tag"
	GitKey    = "git"
	StepIDKey = "stepid"

	SecretFilteringKey = "secret-filtering"
)
View Source
const (
	EnvOAuthIssuer       = "BITRISE_OAUTH_ISSUER"
	EnvOIDCTokenEndpoint = "BITRISE_OIDC_TOKEN_ENDPOINT"
	EnvOAuthClientID     = "BITRISE_OAUTH_CLIENT_ID"
)

Env vars overriding the OAuth defaults below — rarely changed, mostly for pointing a build at a non-prod environment. Exported since tests set them directly.

View Source
const EnvAPIBaseURL = "BITRISE_API_BASE_URL"

EnvAPIBaseURL overrides the API base URL — rarely changed, mostly for pointing at a non-prod environment. Exported since tests set it directly.

View Source
const EnvAppID = "BITRISE_APP_ID"

EnvAppID overrides the app slug when --app isn't passed.

View Source
const EnvAppIDLegacy = "BITRISE_APP_SLUG"

EnvAppIDLegacy is the pre-rename name, still accepted below EnvAppID. Bitrise auto-injects it into every build to identify the app the build runs for (see analytics/tracker.go, configs/agent_config.go), so honoring it means a bare command inside app X's build targets app X — including `bitrise yml update`, which then overwrites that app's own bitrise.yml. That ambient targeting is intentional and matches the released CLI.

View Source
const EnvOutput = "BITRISE_OUTPUT"

EnvOutput overrides the output format when neither --output nor the "output" config key is set.

View Source
const EnvRDEAPIBaseURL = "BITRISE_RDE_API_BASE_URL"

EnvRDEAPIBaseURL overrides the RDE API base URL — rarely changed, mostly for pointing at a non-prod environment. Exported since tests set it directly.

View Source
const EnvTheme = "BITRISE_CLI_THEME"

EnvTheme overrides the color theme when neither --theme nor the "theme" config key is set.

View Source
const EnvVarAnnotation = "bitrise_env_var"

EnvVarAnnotation records the environment variable a flag is bound to. The binding drives both analytics (a flag is reported as set when its value comes from the env) and the flag/env mode resolution (see ResolveBoolFlagOrEnv).

View Source
const EnvWebBaseURL = "BITRISE_WEB_BASE_URL"

EnvWebBaseURL overrides the web base URL — rarely changed, mostly for pointing a build at a non-prod environment. Exported since tests set it directly.

View Source
const EnvWorkspaceID = workspace.EnvWorkspaceID

EnvWorkspaceID supplies the workspace when --workspace isn't passed. Bitrise auto-injects it into every build, naming the workspace that owns the app the build runs for, so a bare command inside a build acts on that workspace. Same intentional ambient targeting as EnvAppIDLegacy. Defined in internal/workspace because the shared sole-workspace error names it.

View Source
const FlagApp = "app"

FlagApp is the app slug a command acts on.

View Source
const FlagNoColor = "no-color"

FlagNoColor disables ANSI colors regardless of terminal detection.

View Source
const FlagOutput = "output"

FlagOutput is the root-persistent output format flag (raw|json|yml, plus the human alias for raw). Per-command --format flags (FormatKey) take precedence over it when set.

View Source
const FlagQuiet = "quiet"

FlagQuiet suppresses non-error diagnostic messages. Only rde commands act on it for now (see IsQuiet).

View Source
const FlagTheme = "theme"

FlagTheme selects the color theme (see internal/style.Themes).

View Source
const FlagWorkspace = "workspace"

FlagWorkspace is the workspace a command acts on.

Variables

View Source
var ErrNoBitriseConfigFound = errors.New("bitrise.yml path not defined and not found on it's default path")

ErrNoBitriseConfigFound is returned when no config path was given and there is no bitrise.yml on the default path. Callers that treat "nothing to validate" as a no-op rather than a failure match on it with errors.Is.

View Source
var ErrNoToken = errors.New("no Bitrise access token configured (run 'bitrise auth login' or set BITRISE_TOKEN)")

GlobalFlagNames lists the persistent flags that configure bitrise itself. They are recognised on the plugin/envman dispatch paths and reported to analytics, so the list is shared rather than repeated at each use site.

View Source
var IsTerminal = func(r io.Reader) bool {
	_, ok := TerminalFd(r)
	return ok
}

IsTerminal reports whether r is an interactive terminal. Pipes and buffers never are, so callers can pick an interactive default (e.g. browser login) while keeping non-interactive stdin (CI, pipes) working.

It's a var, not a func, so tests can substitute it to exercise branches that depend on an actual TTY (e.g. cli/auth/login.go's SSH-vs-browser default) without one.

Functions

func AddAppFlag

func AddAppFlag(fs *pflag.FlagSet, help string)

AddAppFlag registers --app. Registered per-subcommand rather than as a persistent parent flag, since some of these commands are also re-registered standalone as legacy top-level aliases (see cli/root.go) that never attach to the yml parent.

func AddConfigAndInventoryFlags

func AddConfigAndInventoryFlags(fs *pflag.FlagSet)

AddConfigAndInventoryFlags ...

func AddJSONParamsFlags

func AddJSONParamsFlags(fs *pflag.FlagSet)

AddJSONParamsFlags ...

func AddSecretFilteringFlag

func AddSecretFilteringFlag(fs *pflag.FlagSet)

AddSecretFilteringFlag ...

func AddTriggerFilterFlags

func AddTriggerFilterFlags(fs *pflag.FlagSet)

AddTriggerFilterFlags ...

func AppSlugIsUserProvided

func AppSlugIsUserProvided(cmd *cobra.Command, args []string) bool

AppSlugIsUserProvided reports whether the app slug ResolveAppSlug / ResolveAppSlugArg / LookupAppSlug would return for cmd/args came from something the user typed (--app, or a positional argument in args) rather than an ambient source (BITRISE_APP_ID/BITRISE_APP_SLUG, saved config). Only a user-provided value can be a display name — ambient ones are always already a canonical slug — so callers that resolve a name to a slug themselves (rather than through ResolveAndLookupAppSlug) use this to skip that lookup, and its API call, for ambient values.

func AppSlugRequiredErr

func AppSlugRequiredErr() error

AppSlugRequiredErr returns the standard missing-app-slug error.

func ApplyGlobalFlagsFromArgs

func ApplyGlobalFlagsFromArgs(root *cobra.Command, args []string, globalFlagNames []string)

ApplyGlobalFlagsFromArgs sets the global flags on the plugin/envman dispatch paths, where cobra does not parse them. Only the leading args (before the command token) are bitrise globals; anything after belongs to the passthrough.

func AsHidden

func AsHidden(cmd *cobra.Command) *cobra.Command

AsHidden marks cmd as hidden and returns it.

func CheckFormatVersionSupported

func CheckFormatVersionSupported(configFormatVersion string) error

CheckFormatVersionSupported errors when configFormatVersion is newer than the format version this CLI supports (models.FormatVersion). A bitrise.yml requesting a newer format may use syntax this CLI version doesn't understand yet, so this is checked separately from schema validity.

func CheckPasswordStdinPiped

func CheckPasswordStdinPiped(passwordStdin, isTerminal bool, exampleCmd string) error

CheckPasswordStdinPiped reports an error when --password-stdin is set but stdin is an interactive terminal rather than a pipe. Falling through to a plain (non-masked) read in that case would block on terminal input with local echo still on, silently printing the password to the screen. exampleCmd is the invocation shown in the error's pipe example, e.g. "bitrise auth login --email <email>".

func CheckUpdate

func CheckUpdate() error

CheckUpdate ...

func CheckValueStdinPiped

func CheckValueStdinPiped(valueStdin, isTerminal bool, exampleCmd string) error

CheckValueStdinPiped is CheckPasswordStdinPiped's counterpart for commands whose stdin secret arrives under --value-stdin (`rde saved-input`). Same hazard, same shape — only the flag and the prose differ, so they stay as two literal messages rather than one parameterized template.

func CommandTokenIndex

func CommandTokenIndex(fs *pflag.FlagSet, args []string, globalFlagNames []string) int

CommandTokenIndex returns the index of the first argument that is not a global flag — the command/plugin/positional token. Global flags before this boundary configure bitrise; everything from it onward belongs to the command (and, for plugins and envman, is forwarded verbatim), so it must not be scanned for or stripped of global flags.

fs is the root's persistent flag set. It supplies each global's shorthand and whether it takes a value, so this scanner accepts the same spellings cobra would: a bare "--output"/"-o" is followed by its value, not by the command/plugin token, and that value must be skipped rather than mistaken for it.

func CreateBitriseConfigFromCLIParams

func CreateBitriseConfigFromCLIParams(bitriseConfigBase64Data, bitriseConfigPath string, validation bitrise.ValidationType) (models.BitriseDataModel, []string, error)

CreateBitriseConfigFromCLIParams ...

func CreateDefaultMerger

func CreateDefaultMerger() (*configmerge.Merger, error)

CreateDefaultMerger ...

func CreateInventoryFromCLIParams

func CreateInventoryFromCLIParams(inventoryBase64Data, inventoryPath string) ([]envmanModels.EnvironmentItemModel, error)

CreateInventoryFromCLIParams ...

func DefaultWorkspaceSlug

func DefaultWorkspaceSlug(cmd *cobra.Command) string

DefaultWorkspaceSlug returns the workspace configured as the default — BITRISE_WORKSPACE_ID, then the default_workspace_id config key — or "" when neither is set. It deliberately does not read --workspace: callers own that flag's precedence, and they need to know whether a value came from the flag (explicit) or from here (implicit) to report it to the user.

func DelegateToList

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

DelegateToList forwards a bare parent invocation to its "list" subcommand, propagating the parent's context so resolved config is available.

Invoking RunE bypasses cobra's execute(), so the two things it would do for the subcommand are done here instead: InheritedFlags is called for its side effect of merging the parent chain's persistent flags (e.g. --workspace) into the subcommand's flagset, and required flags are validated explicitly.

func DetectSingleDashLongFlag

func DetectSingleDashLongFlag(cmd *cobra.Command, args []string) (arg, flagName string, found bool)

DetectSingleDashLongFlag reports the first argument in args that spells a long flag name of cmd with a single dash instead of "--" (e.g. "-config"). Left to pflag, this either silently misparses as a shorthand cluster with an attached value (when the leading character happens to be a registered shorthand, e.g. "-config" becomes "-c" with value "onfig") or is rejected with a cryptic "unknown shorthand flag" error — so callers should reject it outright rather than let cobra parse it. cmd should be the resolved target command (e.g. via (*cobra.Command).Find), since a flag name is only meaningful relative to the command it is reachable on.

Tokens that pflag would consume as a preceding flag's value are skipped: pflag takes the next argument verbatim even when it starts with a dash, so `--commit-message -tag` legitimately sets the message to "-tag" and must not be mistaken for a misspelled --tag.

func Failf

func Failf(format string, args ...interface{})

Failf prints a formatted error to stderr and exits the process with status 1. It must not go through the global logger (log.Errorf): that logger's writer is stdout, which would leak the error into piped machine-readable output (e.g. `stack list -o json | jq`), and re-pointing the global logger would also move `bitrise run`'s step output to stderr with it.

func GetBitriseConfigFilePath

func GetBitriseConfigFilePath(bitriseConfigPath string) (string, error)

GetBitriseConfigFilePath ...

func GetBitriseConfigFromBase64Data

func GetBitriseConfigFromBase64Data(configBase64Str string, validation bitrise.ValidationType) (models.BitriseDataModel, []string, error)

GetBitriseConfigFromBase64Data ...

func GetInventoryFilePath

func GetInventoryFilePath(inventoryPath string) (string, error)

GetInventoryFilePath ...

func GetInventoryFromBase64Data

func GetInventoryFromBase64Data(inventoryBase64Str string) ([]envmanModels.EnvironmentItemModel, error)

GetInventoryFromBase64Data ...

func GlobalFlagValuesFromArgs

func GlobalFlagValuesFromArgs(fs *pflag.FlagSet, args, globalFlagNames []string) map[string]string

GlobalFlagValuesFromArgs returns the values the leading global flags in args assign, keyed by flag name. It reads the same tokens ApplyGlobalFlagsFromArgs would set, without touching the command — for callers that need a global's value before cobra has parsed anything.

func InstalledWithBrew

func InstalledWithBrew() (bool, error)

InstalledWithBrew ...

func IsCIMode

func IsCIMode(ciGlobalFlagPtr *bool, inventoryEnvironments []envmanModels.EnvironmentItemModel) (bool, error)

IsCIMode ...

func IsFlag

func IsFlag(name, arg string) bool

IsFlag reports whether arg is the long flag --name or --name=value. Only the double-dash spelling is recognised, matching cobra/pflag: bitrise's long flags have no single-dash form.

func IsPRMode

func IsPRMode(prGlobalFlagPtr *bool, inventoryEnvironments []envmanModels.EnvironmentItemModel) (bool, error)

IsPRMode ...

func IsQuiet

func IsQuiet(cmd *cobra.Command) bool

IsQuiet reports whether the persistent --quiet flag was set.

func IsSSHSession

func IsSSHSession() bool

IsSSHSession reports whether the CLI is running inside an SSH session, where OpenBrowser would try to launch a browser on the remote host and the OAuth loopback redirect could never reach back to this process.

func IsSecretEnvsFiltering

func IsSecretEnvsFiltering(filteringFlag *bool, inventoryEnvironments []envmanModels.EnvironmentItemModel) (bool, error)

IsSecretEnvsFiltering ...

func IsSecretFiltering

func IsSecretFiltering(filteringFlag *bool, inventoryEnvironments []envmanModels.EnvironmentItemModel) (bool, error)

IsSecretFiltering ...

func IsSteplibOfflineMode

func IsSteplibOfflineMode() bool

IsSteplibOfflineMode ...

func IsTerminalWriter

func IsTerminalWriter(w io.Writer) bool

IsTerminalWriter reports whether w is an interactive terminal, e.g. for gating pretty-printing so piped or redirected output isn't reformatted.

func JoinShellArgs

func JoinShellArgs(args []string) string

JoinShellArgs joins argv into a single shell-safe command string by POSIX-quoting each argument. Without quoting, `bash -c 'echo a; pwd'` would arrive at the remote as three space-separated tokens and the `;` would be reinterpreted by the remote shell, dropping `echo a`.

func LatestTag

func LatestTag() (*ver.Version, error)

LatestTag ...

func LogCommandParameters

func LogCommandParameters(cmd *cobra.Command)

LogCommandParameters ...

func LogPluginCommandParameters

func LogPluginCommandParameters(name string, _ []string)

LogPluginCommandParameters ...

func LookupAppSlug

func LookupAppSlug(cmd *cobra.Command) string

LookupAppSlug resolves the app slug the same way as ResolveAppSlug but returns an empty string instead of an error when neither source is set — for commands where the app is optional (e.g. `yml validate --app`).

func NewAPIClient

func NewAPIClient(cmd *cobra.Command) (*bitriseapi.Client, error)

NewAPIClient builds a *bitriseapi.Client using the token resolved by liveToken and the resolved API base URL.

func NewCLIVersion

func NewCLIVersion() (string, error)

NewCLIVersion ...

func NewRDEClient

func NewRDEClient(cmd *cobra.Command) (*rdeapi.Client, error)

NewRDEClient builds an *rdeapi.Client using the token resolved by liveToken and the resolved RDE API base URL.

func NewResolver

func NewResolver(client *bitriseapi.Client) *resolve.Resolver

NewResolver returns a Resolver wired to client and a fresh in-memory cache, so repeated lookups within one command invocation hit the API once.

func NewVersionFromBrew

func NewVersionFromBrew() (string, error)

NewVersionFromBrew ...

func OAuthConfig

func OAuthConfig() oauth.Config

OAuthConfig builds the oauth.Config from env-var overrides, falling back to production defaults.

func OSDisplayName

func OSDisplayName(os string) string

OSDisplayName maps a backend OS token to a human-friendly display name (e.g. "macos" → "macOS", "linux" → "Linux"); unknown values pass through unchanged. Shared by the RDE stack list and the `rde claude` stack picker so the capitalization stays consistent. This is display-only — the raw token is still what `--output json` and the wire carry.

func OpenBrowser

func OpenBrowser(url string) error

OpenBrowser opens url in the system default browser.

func OpenVNCURL

func OpenVNCURL(ctx context.Context, url string) error

OpenVNCURL invokes the OS's default URL handler for a vnc:// URL:

  • macOS: open
  • Windows: cmd /c start
  • other: xdg-open

Errors carry the handler's combined output so a missing xdg-open or a malformed URL is debuggable without rerunning under strace.

The vnc:// prefix is verified before shelling out. The URL is built from backend-provided host/port plus URL-escaped credentials, but the call can be triggered by a remote signal (the rde claude host bridge), so the prefix check is the trust boundary that keeps a non-vnc argument from reaching the OS handler.

func PrintCLIUpdateInfos

func PrintCLIUpdateInfos(newVersion string)

PrintCLIUpdateInfos ...

func ReadPasswordInput

func ReadPasswordInput(in io.Reader, stderr io.Writer, prompt string, fromStdin bool) (string, error)

ReadPasswordInput reads a password from in the same way as ReadSecretInput, but trims only a trailing line terminator — a leading/trailing space can be a deliberate part of a password and must not be silently stripped.

func ReadSecretInput

func ReadSecretInput(in io.Reader, stderr io.Writer, prompt string, fromStdin bool) (string, error)

ReadSecretInput reads a secret from in, trimming all surrounding whitespace (tokens are forgiving of shell copy/paste artifacts). When fromStdin is true, or in isn't a terminal, it reads a line directly; otherwise it prompts and reads a masked line.

func RegisterCIMode

func RegisterCIMode(isCIMode bool) error

RegisterCIMode ...

func RegisterPrMode

func RegisterPrMode(isPRMode bool) error

RegisterPrMode ...

func RegisterSecretEnvsFiltering

func RegisterSecretEnvsFiltering(filtering bool) error

RegisterSecretEnvsFiltering ...

func RegisterSecretFiltering

func RegisterSecretFiltering(filtering bool) error

RegisterSecretFiltering ...

func RegisterSteplibOfflineMode

func RegisterSteplibOfflineMode(offlineMode bool)

RegisterSteplibOfflineMode ...

func RequireArgs

func RequireArgs(names ...string) cobra.PositionalArgs

RequireArgs returns an Args validator that names exactly which positional argument(s) are missing, instead of cobra's generic "accepts N arg(s), received M".

func RequireKnownSubcommand

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

RequireKnownSubcommand is the RunE for parent commands that only dispatch to subcommands (they have no action of their own): show help when invoked bare, and error on an unknown subcommand instead of silently succeeding.

func ResolveAPIBaseURL

func ResolveAPIBaseURL(cmd *cobra.Command) string

ResolveAPIBaseURL returns the resolved API base URL: BITRISE_API_BASE_URL, then the api_base_url set via `bitrise config set` (global config file only — never a per-dir .bitrise-cli.yml, see internal/config.Resolve), then the built-in default — matching ResolveWebBaseURL/ResolveRDEAPIBaseURL. Any trailing slash is trimmed here, once, so every caller can concatenate a path onto the result without producing a double slash.

func ResolveAndLookupAppSlug

func ResolveAndLookupAppSlug(cmd *cobra.Command, client *bitriseapi.Client) (string, error)

ResolveAndLookupAppSlug reads the app slug from --app, falling back to BITRISE_APP_ID, then BITRISE_APP_SLUG, then config app_id. Only a --app value goes through the name lookup (a targeted GET /apps?title=<value> query) — the ambient sources are already a canonical slug, so resolving those would just be a wasted API call.

func ResolveAndLookupWorkspaceSlug

func ResolveAndLookupWorkspaceSlug(cmd *cobra.Command, client *bitriseapi.Client, flagValue string) (slug string, usedDefault bool, err error)

ResolveAndLookupWorkspaceSlug resolves a command's --workspace flag value (flagValue), falling back to DefaultWorkspaceSlug (BITRISE_WORKSPACE_ID / default_workspace_id). Only flagValue is resolved by name (a lookup against GET /organizations, since --workspace can be a display name) — the fallback is always already a canonical slug (Bitrise-injected or previously saved by this CLI as a slug), so it's used verbatim without an extra request. usedDefault reports whether the value came from the fallback, for callers that print a "using default workspace" breadcrumb.

func ResolveAppSlug

func ResolveAppSlug(cmd *cobra.Command) (string, error)

ResolveAppSlug returns the app slug from --app, falling back to BITRISE_APP_ID, then BITRISE_APP_SLUG, then the app_id set by `bitrise app create` or `bitrise config set app_id`.

func ResolveAppSlugArg

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

ResolveAppSlugArg is ResolveAppSlug for commands that also accept the app slug as a positional argument (e.g. `app view [APP_ID]`), which takes precedence over --app/BITRISE_APP_ID/config when given.

func ResolveBoolEnv

func ResolveBoolEnv(envKey string) (*bool, error)

ResolveBoolEnv resolves a bool from an env var: nil when unset or empty, the parsed value otherwise. A non-bool value is an error.

func ResolveBoolFlagOrEnv

func ResolveBoolFlagOrEnv(fs *pflag.FlagSet, name string) (*bool, error)

ResolveBoolFlagOrEnv resolves a bool flag that may be bound to an env var via SetFlagEnvVar. Precedence: explicit flag > bound env > nil.

func ResolveRDEAPIBaseURL

func ResolveRDEAPIBaseURL(cmd *cobra.Command) string

ResolveRDEAPIBaseURL returns the resolved RDE API base URL: BITRISE_RDE_API_BASE_URL, then the rde_api_base_url set via `bitrise config set` (global config file only — never a per-dir .bitrise-cli.yml, see internal/config.Resolve), then the built-in default. Any trailing slash is trimmed here, once, so every caller can concatenate a path onto the result without producing a double slash.

func ResolveToken

func ResolveToken() (token string, fromEnv bool, err error)

ResolveToken returns the configured token and whether it came from the BITRISE_TOKEN environment variable (true) or auth.yaml (false), without refreshing it. token is empty when neither is set; err is non-nil only on an unexpected auth.yaml load failure (a missing file is not an error).

func ResolveWebBaseURL

func ResolveWebBaseURL(cmd *cobra.Command) string

ResolveWebBaseURL returns the resolved web base URL: BITRISE_WEB_BASE_URL, then the web_base_url set via `bitrise config set` (global config file only — never a per-dir .bitrise-cli.yml, see internal/config.Resolve), then the built-in default. Any trailing slash is trimmed here, once, so every caller can concatenate a path onto the result without producing a double slash — the built-in default carries none, but a user-set value might.

func ResolveWorkspaceID

func ResolveWorkspaceID(cmd *cobra.Command) (string, error)

ResolveWorkspaceID returns the workspace ID for this command: --workspace, then DefaultWorkspaceSlug (BITRISE_WORKSPACE_ID / default_workspace_id), then one GET /organizations call — a sole workspace auto-detects (with a stderr breadcrumb), 2+ workspaces show an interactive picker on a TTY or a friendly sorted error otherwise. Zero workspaces always errors.

func SendCommandInfo

func SendCommandInfo(command, subcommand string, flags []string)

SendCommandInfo ...

func SetFlagEnvVar

func SetFlagEnvVar(fs *pflag.FlagSet, name, envKey string)

SetFlagEnvVar binds a flag to an environment variable.

func SetTracker

func SetTracker(t analytics.Tracker)

SetTracker sets the package-level tracker used by LogCommandParameters, LogPluginCommandParameters and Failf.

func ShellQuote

func ShellQuote(s string) string

ShellQuote wraps s in POSIX single-quotes, escaping any embedded single quotes with the standard `'\”` sequence. Strings made entirely of shell-safe characters are returned as-is to keep readable commands readable in logs.

func ShowSubcommandHelp

func ShowSubcommandHelp(cmd *cobra.Command)

ShowSubcommandHelp prints cmd's help output.

func SilenceRootErrors

func SilenceRootErrors(cmd *cobra.Command)

SilenceRootErrors prevents cobra from printing a returned error to stderr by setting SilenceErrors on both the command and its root. Use this when the command has already printed its own error summary and the automatic "Error: ..." line would be redundant.

func TerminalFd

func TerminalFd(stream any) (fd int, isTerminal bool)

TerminalFd reports whether stream is an *os.File backed by a TTY. fd is only meaningful when isTerminal is true. A nil stream safely fails the type assertion below and reports false.

func Tracker

func Tracker() analytics.Tracker

Tracker returns the package-level tracker set via SetTracker.

Types

type ErrWriter

type ErrWriter struct {
	Err error
	// contains filtered or unexported fields
}

ErrWriter wraps an io.Writer and captures the first write error so callers can chain writes and check once at the end.

func NewErrWriter

func NewErrWriter(w io.Writer) *ErrWriter

NewErrWriter returns an ErrWriter backed by w.

func (*ErrWriter) F

func (ew *ErrWriter) F(format string, a ...any)

F writes a formatted string, skipping if a previous write already failed.

func (*ErrWriter) Ln

func (ew *ErrWriter) Ln(a ...any)

Ln writes args followed by a newline, skipping if a previous write failed.

type Formatable

type Formatable interface {
	String() string
	JSON() string
}

Formatable ...

type JSONLogger

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

JSONLogger ...

func NewDefaultJSONLogger

func NewDefaultJSONLogger() JSONLogger

NewDefaultJSONLogger ...

func (JSONLogger) Print

func (l JSONLogger) Print(f Formatable)

Print ...

type Logger

type Logger interface {
	Print(f Formatable)
}

Logger ...

type RawLogger

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

RawLogger ...

func NewDefaultRawLogger

func NewDefaultRawLogger() RawLogger

NewDefaultRawLogger ...

func (RawLogger) Print

func (l RawLogger) Print(f Formatable)

Print ...

type YAMLLogger

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

YAMLLogger ...

func NewDefaultYAMLLogger

func NewDefaultYAMLLogger() YAMLLogger

NewDefaultYAMLLogger ...

func (YAMLLogger) Print

func (l YAMLLogger) Print(f Formatable)

Print marshals the concrete model behind f rather than asking it for a rendering: Formatable has no YAML method, and only the two loggers above need a hand-written one. Models reaching here need yaml tags matching their json tags, like anything else passed to output.Print.

Directories

Path Synopsis
Package picker is a small reusable arrow-key list selector built on bubbletea.
Package picker is a small reusable arrow-key list selector built on bubbletea.

Jump to

Keyboard shortcuts

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