Documentation
¶
Overview ¶
Package clihelpers contains shared nvfleetint command helpers.
Index ¶
- Constants
- Variables
- func Confirm(in io.Reader, out io.Writer, summary string) error
- func ExtractRawItems(data []byte, itemKey string) ([]json.RawMessage, error)
- func OneBasedPage(page, pageSize, total int) int
- func OneIndexRawPage(data []byte) []byte
- func ParseCommaList(raw string) ([]string, error)
- func TotalPages(total, pageSize int) int
- type MergedJSONResult
- type MergedPagination
- type RawPage
Constants ¶
const ( // MinPageSize is the smallest page size accepted by list commands MinPageSize = 1 // MaxPageSize is the largest page size accepted by list commands MaxPageSize = 100 // MaxPages bounds all-page pagination when the API keeps reporting more data MaxPages = 10000 )
Variables ¶
var ErrAborted = errors.New("aborted")
ErrAborted reports a confirmation prompt the user declined. It exits 1 through main.go like any other command error.
Functions ¶
func Confirm ¶
Confirm prints summary and an "Are you sure? y/N" prompt to out and waits for an answer on in. Callers pass the command's stderr as out so `-o json` keeps stdout parseable. Anything other than an explicit yes returns ErrAborted, so the default is No.
It refuses to prompt when in is a non-terminal file, so a cron or CI run gets a clear "re-run with --yes" error instead of blocking forever or silently aborting on EOF.
func ExtractRawItems ¶
func ExtractRawItems(data []byte, itemKey string) ([]json.RawMessage, error)
Extracts raw array items from an API response object
func OneBasedPage ¶
OneBasedPage converts an SDK page to the CLI's 1-based page number and bounds it to the available pages. Empty results are represented as page 0 of 0 so the displayed page never exceeds the total page count.
func OneIndexRawPage ¶
OneIndexRawPage rewrites the 0-indexed "page" field in a raw list payload to its 1-indexed equivalent so JSON consumers see the CLI's paging contract. When total and pageSize are available, the page is bounded to the available pages. The original bytes are returned unchanged when the payload has no usable page field.
func ParseCommaList ¶
Splits a comma-separated flag value into trimmed values
func TotalPages ¶
TotalPages returns the number of pages needed to hold total items.
Types ¶
type MergedJSONResult ¶
type MergedJSONResult struct {
Items []json.RawMessage `json:"items"`
Pagination MergedPagination `json:"pagination"`
}
Represents normalized JSON for all-page output
func FetchAllRawPages ¶
func FetchAllRawPages(itemKey string, startPage int, fetch func(page int) (RawPage, error)) (MergedJSONResult, error)
Fetches and merges raw API item payloads across pages