clihelpers

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package clihelpers contains shared nvfleetint command helpers.

Index

Constants

View Source
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

View Source
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

func Confirm(in io.Reader, out io.Writer, summary string) error

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

func OneBasedPage(page, pageSize, total int) int

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

func OneIndexRawPage(data []byte) []byte

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

func ParseCommaList(raw string) ([]string, error)

Splits a comma-separated flag value into trimmed values

func TotalPages

func TotalPages(total, pageSize int) int

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

type MergedPagination

type MergedPagination struct {
	Page         int  `json:"page"`
	PageSize     int  `json:"pageSize"`
	Total        int  `json:"total"`
	HasMore      bool `json:"hasMore"`
	PagesFetched int  `json:"pagesFetched"`
}

Represents metadata for normalized all-page JSON

type RawPage

type RawPage struct {
	RawJSON  []byte
	Page     int
	PageSize int
	Total    int
	HasMore  *bool
}

Represents one paginated raw API response

Jump to

Keyboard shortcuts

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