Documentation
¶
Index ¶
- func AtomicWrite(path string, data []byte, mode os.FileMode) error
- func BuildConfirmDeleteCommand(cfg ConfirmDeleteCommandConfig) *ffcli.Command
- func BuildPaginatedListCommand(cfg PaginatedListCommandConfig) *ffcli.Command
- func ContextWithDryRun(ctx context.Context, dryRun bool) context.Context
- func ContextWithTimeout(ctx context.Context, cfg *config.Config) (context.Context, context.CancelFunc)
- func ContextWithUploadTimeout(ctx context.Context, cfg *config.Config) (context.Context, context.CancelFunc)
- func DefaultUsageFunc(cmd *ffcli.Command) string
- func DeprecatedAliasLeafCommand(original *ffcli.Command, oldName, newCommandPath string) *ffcli.Command
- func DeriveUpdateMask(raw []byte, mutableFields []string) (string, error)
- func FormatUnknownCommand(input string, commands []string) string
- func IsDryRun(ctx context.Context) bool
- func IsReportedError(err error) bool
- func LevenshteinDistance(a, b string) int
- func LoadJSONArg(value string, out interface{}) error
- func LoadJSONArgRaw(value string) ([]byte, error)
- func NewActionableError(op string, cause error, hint string) error
- func NewAuthError(op string, cause error, hint string) error
- func NewNotFoundError(op string, cause error, hint string) error
- func NewPermissionError(op string, cause error, hint string) error
- func NewReportedError(err error) error
- func NewValidationError(op string, cause error, hint string) error
- func ParseTimeouts(cfg *config.Config) (time.Duration, time.Duration)
- func PrintOutput(data interface{}, format string, pretty bool) error
- func RegisterCIFlags(fs *flag.FlagSet, cf *CIFlags)
- func RequireFlags(flagSet *flag.FlagSet, required ...string) error
- func RequirePackageName(flagValue string, cfg *config.Config) (string, error)
- func ResolveOutputFormat(flagValue string, flagDefault string) string
- func ResolvePackageName(flagValue string, cfg *config.Config) string
- func ResolveProfileName(cfg *config.Config) string
- func SplitCSV(s string) []string
- func SplitUniqueCSV(s string) []string
- func StrictAuthEnabled() bool
- func SuggestCommand(input string, commands []string, maxDistance int) string
- func UsageError(msg string) error
- func UsageErrorf(format string, args ...any) error
- func ValidateCIFlags(cf *CIFlags) error
- func ValidateOutputFlags(output string, pretty bool) error
- func VisibleUsageFunc(cmd *ffcli.Command) string
- func WithSpinner(label string, fn func() error) error
- func WithSpinnerDelayed(label string, delay time.Duration, fn func() error) error
- func WrapActionable(err error, op, hint string) error
- func WrapCommandOutputValidation(cmd *ffcli.Command)
- func WrapGoogleAPIError(op string, err error) error
- func WriteJUnitReport(suites *JUnitTestSuites, filePath string) error
- type ActionableError
- type AuthError
- type CIFlags
- type ConfirmDeleteCommandConfig
- type DryRunTransport
- type JUnitFailure
- type JUnitTestCase
- type JUnitTestSuite
- type JUnitTestSuites
- type NotFoundError
- type OptionalBool
- type OutputFlags
- type PaginatedListCommandConfig
- type PermissionError
- type ProgressReader
- type ReportedError
- type RootFlags
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicWrite ¶ added in v0.4.8
AtomicWrite writes data to path atomically using a temp-file-then-rename pattern. This prevents corruption if the process crashes during the write.
func BuildConfirmDeleteCommand ¶ added in v0.4.8
func BuildConfirmDeleteCommand(cfg ConfirmDeleteCommandConfig) *ffcli.Command
BuildConfirmDeleteCommand creates a standard delete command requiring --confirm.
func BuildPaginatedListCommand ¶ added in v0.4.8
func BuildPaginatedListCommand(cfg PaginatedListCommandConfig) *ffcli.Command
BuildPaginatedListCommand creates a standard list command with --page-size, --paginate, --next, --output, and --pretty flags.
func ContextWithDryRun ¶ added in v0.4.2
ContextWithDryRun returns a context with the dry-run flag set.
func ContextWithTimeout ¶
func ContextWithTimeout(ctx context.Context, cfg *config.Config) (context.Context, context.CancelFunc)
ContextWithTimeout applies request timeouts.
func ContextWithUploadTimeout ¶
func ContextWithUploadTimeout(ctx context.Context, cfg *config.Config) (context.Context, context.CancelFunc)
ContextWithUploadTimeout applies upload timeouts.
func DefaultUsageFunc ¶
DefaultUsageFunc renders help output for any command with formatted sections.
func DeprecatedAliasLeafCommand ¶ added in v0.4.8
func DeprecatedAliasLeafCommand(original *ffcli.Command, oldName, newCommandPath string) *ffcli.Command
DeprecatedAliasLeafCommand creates a deprecated alias that wraps an existing command. When invoked, it prints a deprecation warning to stderr then runs the original command. The alias is hidden from parent help via the "DEPRECATED:" prefix in ShortHelp.
func DeriveUpdateMask ¶ added in v0.4.9
DeriveUpdateMask extracts top-level keys from raw JSON and returns a sorted, comma-separated update mask containing only keys that appear in mutableFields.
We use an allowlist rather than a blocklist because the CLI unmarshals JSON into typed SDK structs before sending. The SDK drops unknown fields during unmarshal, so including an unknown key in the mask would create a mismatch (mask names a field the body doesn't contain) and cause a guaranteed 400.
func FormatUnknownCommand ¶ added in v0.4.2
FormatUnknownCommand returns an error message with an optional suggestion.
func IsReportedError ¶
IsReportedError returns true if err is a ReportedError.
func LevenshteinDistance ¶ added in v0.4.2
LevenshteinDistance computes the edit distance between two strings.
func LoadJSONArg ¶
LoadJSONArg parses JSON from a literal string or @file path.
func LoadJSONArgRaw ¶ added in v0.4.9
LoadJSONArgRaw returns the raw JSON bytes from a literal string or @file path without unmarshaling. Use this when you need to inspect the JSON keys before parsing into a typed struct.
func NewActionableError ¶
NewActionableError builds an ActionableError.
func NewAuthError ¶
NewAuthError builds an AuthError.
func NewNotFoundError ¶
NewNotFoundError builds a NotFoundError.
func NewPermissionError ¶
NewPermissionError builds a PermissionError.
func NewReportedError ¶
NewReportedError wraps err as ReportedError.
func NewValidationError ¶
NewValidationError builds a ValidationError.
func PrintOutput ¶
PrintOutput renders output in the requested format.
func RegisterCIFlags ¶ added in v0.4.4
RegisterCIFlags adds --report and --report-file flags to a flag set.
func RequireFlags ¶
RequireFlags ensures the required flags are provided.
func RequirePackageName ¶ added in v0.4.8
RequirePackageName resolves the package name and returns an error if not found.
func ResolveOutputFormat ¶ added in v0.4.2
ResolveOutputFormat returns the output format to use based on flag and env var. If flagValue is non-empty and not the default, it takes precedence. Otherwise falls back to GPLAY_DEFAULT_OUTPUT, then "json".
func ResolvePackageName ¶
ResolvePackageName returns a package name from flags/env/config.
func ResolveProfileName ¶
ResolveProfileName returns the selected profile name.
func SplitCSV ¶ added in v0.4.8
SplitCSV splits a comma-separated string, trims whitespace from each element, and removes empty strings.
func SplitUniqueCSV ¶ added in v0.4.8
SplitUniqueCSV splits a comma-separated string, trims whitespace, removes empties, and deduplicates (preserving first occurrence order).
func StrictAuthEnabled ¶
func StrictAuthEnabled() bool
func SuggestCommand ¶ added in v0.4.2
SuggestCommand finds the closest command name within maxDistance.
func UsageError ¶ added in v0.4.8
UsageError prints msg to stderr and returns flag.ErrHelp. This is the standard way to report missing/invalid flags. It results in exit code 2 (usage error) when structured exit codes are wired.
func UsageErrorf ¶ added in v0.4.8
UsageErrorf is like UsageError but with fmt.Sprintf formatting.
func ValidateCIFlags ¶ added in v0.4.4
ValidateCIFlags checks that the flag values are valid.
func ValidateOutputFlags ¶
ValidateOutputFlags enforces output/pretty compatibility.
func VisibleUsageFunc ¶ added in v0.4.8
VisibleUsageFunc renders help for a command, hiding deprecated subcommands. A subcommand is considered deprecated if its ShortHelp starts with "DEPRECATED:".
func WithSpinner ¶ added in v0.4.4
WithSpinner wraps fn with a braille spinner on stderr. If fn is nil, it returns nil immediately. If fn returns an error, WithSpinner returns it. If fn panics, the spinner stops and the panic is re-raised.
func WithSpinnerDelayed ¶ added in v0.4.4
WithSpinnerDelayed wraps fn with a spinner that only appears after delay. Useful for operations that may complete quickly — no visual noise for fast calls.
func WrapActionable ¶
WrapActionable wraps err with context and an optional hint.
func WrapCommandOutputValidation ¶ added in v0.4.8
WrapCommandOutputValidation recursively wraps all commands' Exec functions to validate output format flags before execution. This prevents API calls when invalid output flags are passed.
func WrapGoogleAPIError ¶
WrapGoogleAPIError adds contextual hints for common Google API failures.
func WriteJUnitReport ¶ added in v0.4.4
func WriteJUnitReport(suites *JUnitTestSuites, filePath string) error
WriteJUnitReport writes JUnit XML to the specified file.
Types ¶
type ActionableError ¶
ActionableError adds context and an optional hint to an error.
func (*ActionableError) Error ¶
func (e *ActionableError) Error() string
func (*ActionableError) Unwrap ¶
func (e *ActionableError) Unwrap() error
type AuthError ¶
type AuthError struct{ ActionableError }
AuthError represents authentication failures.
type CIFlags ¶ added in v0.4.4
type CIFlags struct {
Report string // "junit" or empty
ReportFile string // output file path (default: "results.xml")
}
CIFlags holds CI report configuration.
type ConfirmDeleteCommandConfig ¶ added in v0.4.8
type ConfirmDeleteCommandConfig struct {
Name string
ShortUsage string
ShortHelp string
LongHelp string
// ExtraFlags registers additional command-specific flags.
ExtraFlags func(fs *flag.FlagSet)
// Exec is called only if --confirm is true.
Exec func(ctx context.Context) error
}
ConfirmDeleteCommandConfig configures a standard delete command with --confirm.
type DryRunTransport ¶ added in v0.4.2
type DryRunTransport struct {
Base http.RoundTripper
Writer io.Writer // output destination (typically os.Stderr)
}
DryRunTransport wraps an http.RoundTripper and intercepts write requests when dry-run mode is active. GET/HEAD requests pass through normally. Write requests (POST, PUT, PATCH, DELETE) are logged to stderr and return a synthetic 200 OK response without making any actual API call.
type JUnitFailure ¶ added in v0.4.4
type JUnitFailure struct {
Message string `xml:"message,attr"`
Type string `xml:"type,attr"`
Body string `xml:",chardata"`
}
JUnitFailure represents a test failure.
type JUnitTestCase ¶ added in v0.4.4
type JUnitTestCase struct {
XMLName xml.Name `xml:"testcase"`
Name string `xml:"name,attr"`
ClassName string `xml:"classname,attr"`
Time float64 `xml:"time,attr"`
Failure *JUnitFailure `xml:"failure,omitempty"`
}
JUnitTestCase represents a single test case.
type JUnitTestSuite ¶ added in v0.4.4
type JUnitTestSuite struct {
XMLName xml.Name `xml:"testsuite"`
Name string `xml:"name,attr"`
Tests int `xml:"tests,attr"`
Failures int `xml:"failures,attr"`
Errors int `xml:"errors,attr"`
Time float64 `xml:"time,attr"`
Cases []JUnitTestCase `xml:"testcase"`
}
JUnitTestSuite represents a single test suite.
type JUnitTestSuites ¶ added in v0.4.4
type JUnitTestSuites struct {
XMLName xml.Name `xml:"testsuites"`
Suites []JUnitTestSuite `xml:"testsuite"`
}
JUnitTestSuites is the top-level XML element.
func NewJUnitFromValidation ¶ added in v0.4.4
func NewJUnitFromValidation(validationName string, errors []string, warnings []string, durationSecs float64) *JUnitTestSuites
NewJUnitFromValidation converts validation results into JUnit format. validationName is the suite name (e.g., "bundle", "listing", "screenshots"). errors are test failures, warnings are passed-with-warnings.
type NotFoundError ¶
type NotFoundError struct{ ActionableError }
NotFoundError represents missing resources.
type OptionalBool ¶ added in v0.4.4
type OptionalBool struct {
// contains filtered or unexported fields
}
OptionalBool is a tri-state boolean: unset, true, or false. It implements flag.Value and reports IsBoolFlag() = true so --flag (without value) sets it to true.
func (*OptionalBool) IsBoolFlag ¶ added in v0.4.4
func (o *OptionalBool) IsBoolFlag() bool
IsBoolFlag tells the flag package this can be used without "=value".
func (*OptionalBool) IsSet ¶ added in v0.4.4
func (o *OptionalBool) IsSet() bool
IsSet reports whether the flag was explicitly set.
func (*OptionalBool) Set ¶ added in v0.4.4
func (o *OptionalBool) Set(s string) error
Set implements flag.Value. Accepts: true, false, 1, 0, yes, no (case-insensitive).
func (*OptionalBool) String ¶ added in v0.4.4
func (o *OptionalBool) String() string
String implements flag.Value.
func (*OptionalBool) Value ¶ added in v0.4.4
func (o *OptionalBool) Value() bool
Value returns the boolean value (only meaningful when IsSet is true).
type OutputFlags ¶ added in v0.4.8
OutputFlags holds the parsed output format flags.
func BindOutputFlags ¶ added in v0.4.8
func BindOutputFlags(fs *flag.FlagSet) *OutputFlags
BindOutputFlags registers --output and --pretty flags on the given FlagSet. The default for --output is TTY-aware: "table" if stdout is a terminal, "json" otherwise. The GPLAY_DEFAULT_OUTPUT env var overrides the default.
func (*OutputFlags) Format ¶ added in v0.4.8
func (o *OutputFlags) Format() string
Format returns the resolved output format string.
func (*OutputFlags) IsPretty ¶ added in v0.4.8
func (o *OutputFlags) IsPretty() bool
IsPretty returns whether pretty-printing is enabled.
type PaginatedListCommandConfig ¶ added in v0.4.8
type PaginatedListCommandConfig struct {
Name string
ShortUsage string
ShortHelp string
LongHelp string
// ExtraFlags registers additional command-specific flags.
ExtraFlags func(fs *flag.FlagSet)
// Exec is called with the parsed pagination and output settings.
Exec func(ctx context.Context, pageSize int, pageToken string, paginate bool, output *OutputFlags) error
}
PaginatedListCommandConfig configures a standard paginated list command.
type PermissionError ¶
type PermissionError struct{ ActionableError }
PermissionError represents permission/authorization failures.
type ProgressReader ¶ added in v0.4.2
type ProgressReader struct {
// contains filtered or unexported fields
}
ProgressReader wraps an io.Reader and reports progress to stderr.
func NewProgressReader ¶ added in v0.4.2
func NewProgressReader(r io.Reader, total int64, filename string) *ProgressReader
NewProgressReader creates a progress-reporting reader. If stderr is not a TTY, output is disabled. total can be 0 if unknown.
type ReportedError ¶
type ReportedError struct{ Err error }
ReportedError wraps errors that already have user-facing output.
func (ReportedError) Error ¶
func (r ReportedError) Error() string
func (ReportedError) Unwrap ¶
func (r ReportedError) Unwrap() error
type RootFlags ¶ added in v0.4.8
type RootFlags struct {
Profile *string
Debug *bool
DryRun *bool
Report *string
ReportFile *string
}
RootFlags holds the parsed root-level flags.
func BindRootFlags ¶ added in v0.4.8
BindRootFlags registers root-level flags on the given FlagSet.
func (*RootFlags) Apply ¶ added in v0.4.8
func (rf *RootFlags) Apply()
Apply sets environment variables based on parsed root flags. Call this after root.Parse() and before root.Run().
func (*RootFlags) ValidateReportFlags ¶ added in v0.4.8
ValidateReportFlags checks that --report and --report-file are used together.
type ValidationError ¶
type ValidationError struct{ ActionableError }
ValidationError represents malformed requests or invalid inputs.