feat(cli): add internal/{text,compat} packages and acceptance scaffold (PR-6)
text/ gh-style display-width string helpers (Truncate / FuzzyAgo / Pluralize)
compat/ server-CLI version skew probe (kubectl) + 24h TTL cache (gh internal/update)
acceptance/contract/ helpers_test.go for in-process cobra exec + golden assert
(uses iostreams.SetForTest singleton replacement; no t.Parallel)
cmdutil/errors.go: AllCodes() + ClassifyHTTPErrorOutputs() bridge for the
contract test suite (no behavior change in error handling)
go-runewidth promoted from indirect to direct (used by text.Truncate for
display-width-aware CJK truncation).
acceptance/contract/helpers_test.go forward-references cmd.NewRootCmd which
is exported in PR-7 — that file does not compile until then by design.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
// Package text holds gh-style string helpers for human-readable CLI output.
|
||||
// All functions are pure (no I/O, no time.Now), making them trivially testable.
|
||||
package text
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Pluralize returns "<n> <thing>" or "<n> <thing>s". Mirrors gh
|
||||
// internal/text/text.go Pluralize signature — simple suffix "s" only;
|
||||
// irregular forms (person/people) are not supported (add PluralizeIrregular
|
||||
// when needed, per spec §2.1).
|
||||
func Pluralize(n int, thing string) string {
|
||||
if n == 1 {
|
||||
return fmt.Sprintf("%d %s", n, thing)
|
||||
}
|
||||
return fmt.Sprintf("%d %ss", n, thing)
|
||||
}
|
||||
Reference in New Issue
Block a user