Documentation
¶
Overview ¶
Package sonarinternal holds helpers shared by `krci sonar` verbs (validation, enum sets, render/format dispatch, error-envelope plumbing). Placed under an `internal/` directory so Go enforces package visibility: only packages below `pkg/cmd/sonar/` may import it.
Index ¶
- Constants
- Variables
- func HandleError(ios *iostreams.IOStreams, outputFormat string, err error) error
- func PageCount(total, pageSize int) int
- func PrintTable(w io.Writer, isTTY bool, headers []string, rows [][]string) error
- func Render[T any](ios *iostreams.IOStreams, outputFormat string, data T, ...) error
- func ValidateEnumCSV(flagName string, values []string, allowed EnumSet) ([]string, error)
- func ValidateNonEmptyFlag(name string, changed bool, value string) error
- func ValidateOutputFormat(format string) error
- func ValidateProjectCommand(cmd *cobra.Command, outputFormat, project, pullRequest, branch string) error
- func ValidateScopeMutex(pullRequest, branch string) error
- type EnumSet
- type TableRenderer
Constants ¶
const MaxPageSize = 500
MaxPageSize is the upper bound on `--page-size` for every paginated sonar verb, mirroring the shared Zod schema cap on portal-side.
const SchemaVersion = "1"
SchemaVersion is the shared JSON envelope version for every `krci sonar *` verb. Bump only when the envelope shape changes in a way scripting consumers must detect (e.g. removal of a previously-required key).
Variables ¶
var ( IssueTypes = newEnumSet("BUG", "VULNERABILITY", "CODE_SMELL") IssueSeverities = newEnumSet("BLOCKER", "CRITICAL", "MAJOR", "MINOR", "INFO") IssueStatuses = newEnumSet("OPEN", "CONFIRMED", "REOPENED", "RESOLVED", "CLOSED") )
Canonical SonarQube enum sets. Keep in sync with the Portal's shared SonarQube schema.
Functions ¶
func HandleError ¶
HandleError is cmdutil.HandleError with the sonar envelope version.
func PageCount ¶
PageCount returns the number of pages of pageSize required to hold total items. Always returns at least 1 so footers never read "page 1 of 0".
func PrintTable ¶
PrintTable is the shared TTY/non-TTY dispatcher for sonar verbs that show a plain 2D table. Styled output for interactive terminals, plain tabwriter output when stdout is piped.
func Render ¶
func Render[T any](ios *iostreams.IOStreams, outputFormat string, data T, renderTable TableRenderer) error
Render dispatches on the `-o` flag: emit the shared `{schemaVersion, data}` JSON envelope for `-o json`, invoke the supplied TableRenderer for `-o table` (the default), or return a validation error for anything else.
func ValidateEnumCSV ¶
ValidateEnumCSV checks every comma-separated/repeated value in values against allowed. flagName is used in error messages. Returns the flattened list of validated items in input order with duplicates collapsed (empty when values is empty).
func ValidateNonEmptyFlag ¶ added in v0.9.0
ValidateNonEmptyFlag rejects a flag that was explicitly supplied with an empty value. changed is true when the flag was set on the command line.
func ValidateOutputFormat ¶
ValidateOutputFormat rejects `-o` values other than "", "table", or "json". An empty string means "use default" (table) and is always valid.
func ValidateProjectCommand ¶
func ValidateProjectCommand(cmd *cobra.Command, outputFormat, project, pullRequest, branch string) error
ValidateProjectCommand runs the standard validator chain used by the three project-scoped verbs (get, gate, issues): output format → Kubernetes-name project key → non-empty --pr / --branch (when supplied) → mutual exclusion of the two scope flags.
func ValidateScopeMutex ¶ added in v0.9.0
ValidateScopeMutex rejects commands that set both --pr and --branch, since SonarQube treats the two as mutually exclusive scope selectors.