Documentation
¶
Index ¶
- Constants
- func AbortUploadSession(ctx context.Context, c *client.Client, kind, sessionID string)
- func AppendQuery(path string, extra url.Values) string
- func ApplyPaginationParams(cmd *cobra.Command, path string, p ListParams) (string, error)
- func AssumeYes(cmd *cobra.Command) bool
- func ClientFromCommand(cmd *cobra.Command) (*client.Client, error)
- func Confirm(cmd *cobra.Command, prompt string) (bool, error)
- func DecodeJSON[T any](resp *http.Response, out *T) error
- func EffectiveLimit(cmd *cobra.Command, resource, flagName string, flagValue, fallbackDefault int) int
- func EnsureSuccessStatus(resp *http.Response) error
- func JSONOutputEnabled(cmd *cobra.Command) bool
- func LooksLikeIDPrefix(identifierLower string) bool
- func PrintJSON(v any) error
- func PrintRawJSON(body []byte) error
- func ReadJSONBody(resp *http.Response) ([]byte, error)
- func RunList[T any](cmd *cobra.Command, c *client.Client, spec ListSpec[T]) error
- func RunPostAction[T any](cmd *cobra.Command, c *client.Client, spec PostActionSpec) error
- func UnauthClientFromCommand(cmd *cobra.Command) (*client.Client, error)
- func UploadFileInChunks(ctx context.Context, c *client.Client, kind, filePath string, ...) (string, error)
- type HTTPStatusError
- type ListParams
- type ListSpec
- type PostActionSpec
- type ResourceRef
Constants ¶
const AllFlagUsage = "Return every item, ignoring pagination"
AllFlagUsage is the shared help text for the --all flag on list commands.
const MaxPromptOptions = 20
MaxPromptOptions caps how many search matches the resolver offers interactively before asking the user to refine the query instead.
const ShowAllLimit = -1
ShowAllLimit is the sentinel the Arcane API uses for "return everything". The backend honours it on every list path: DB-backed lists short-circuit to paginateDBAll (bypassing the 100-item clamp), in-memory Docker lists return the full slice, and the handlers that coerce a zero limit to 20 test for exactly 0 so they leave it alone.
const StartFlagUsage = "Offset for pagination (rounded down to a multiple of --limit on database-backed resources)"
StartFlagUsage is the shared help text for the --start flag on list commands. Database-backed resources (projects, repos, gitops-syncs, environments, registries, users, events, api-keys, roles) derive a page number from start/limit, so an offset that is not a multiple of --limit is rounded down.
Variables ¶
This section is empty.
Functions ¶
func AbortUploadSession ¶ added in v2.9.0
AbortUploadSession deletes a chunked upload session, ignoring errors. Use it when the consume step after a completed upload fails.
func AppendQuery ¶ added in v2.6.0
AppendQuery merges extra query parameters into a path, preserving any that are already present.
func ApplyPaginationParams ¶
ApplyPaginationParams appends limit and start query params to a list path. It preserves any existing query parameters on the path.
func ClientFromCommand ¶
ClientFromCommand returns a configured authenticated client for the command.
func DecodeJSON ¶
DecodeJSON decodes JSON into out and enforces a successful HTTP status.
func EffectiveLimit ¶
func EffectiveLimit(cmd *cobra.Command, resource, flagName string, flagValue, fallbackDefault int) int
EffectiveLimit resolves the final list limit with precedence: explicit flag > per-resource config > global config > fallback default. A limit of ShowAllLimit is passed straight through so that `--limit -1` reaches the server as the documented "return everything" sentinel.
func EnsureSuccessStatus ¶
EnsureSuccessStatus returns an error for non-2xx responses.
func JSONOutputEnabled ¶
JSONOutputEnabled returns true if JSON output is enabled for this command.
func LooksLikeIDPrefix ¶ added in v2.10.0
LooksLikeIDPrefix reports whether identifier could be a hex ID prefix worth scanning the full list for.
func PrintRawJSON ¶ added in v2.6.0
PrintRawJSON pretty-prints a raw JSON document, falling back to the bytes as-is.
func ReadJSONBody ¶ added in v2.6.0
ReadJSONBody enforces a successful HTTP status and returns the raw response body. Use it when a command needs both to decode a response and to echo it verbatim, so that fields the CLI does not model — such as the counts and groups objects on the container, volume, network and gitops-sync list endpoints — survive --json output instead of being dropped by a re-marshal.
func RunPostAction ¶ added in v2.10.0
RunPostAction executes one POST action command as described by spec.
func UnauthClientFromCommand ¶
UnauthClientFromCommand returns a configured unauthenticated client for the command.
func UploadFileInChunks ¶ added in v2.9.0
func UploadFileInChunks(ctx context.Context, c *client.Client, kind, filePath string, showProgress bool) (string, error)
UploadFileInChunks streams a local file to the server through a chunked upload session of the given kind and returns the completed session ID. The file is sent as independently retried chunks so reverse-proxy body limits never see the full size. On failure the session is deleted server-side. When showProgress is true a progress bar is rendered.
Types ¶
type HTTPStatusError ¶
HTTPStatusError represents a non-2xx HTTP response.
func (*HTTPStatusError) Error ¶
func (e *HTTPStatusError) Error() string
type ListParams ¶ added in v2.6.0
type ListParams struct {
// Resource is the canonical resource name used to look up a configured
// per-resource limit. See clitypes.KnownPaginatedResources.
Resource string
// Limit is the value of the command's --limit flag.
Limit int
// FallbackDefault applies when neither the flag nor config supplies a limit.
FallbackDefault int
// Start is the value of the command's --start flag.
Start int
// All requests every item, ignoring pagination entirely.
All bool
}
ListParams describes how a list command wants its results paginated.
type ListSpec ¶ added in v2.10.0
type ListSpec[T any] struct { // Resource names the collection in error messages and the trailing // "Showing x of y <resource>" line. Resource string // Endpoint is the list path (environment already applied). Endpoint string // Params configures pagination from the command's flags. Params ListParams // Query holds extra query parameters, applied after pagination. Query url.Values // JSON selects raw JSON passthrough output. JSON bool Headers []string Row func(T) []string }
ListSpec describes one standard list command: fetch a paginated endpoint, echo the raw body for --json (so unmodeled fields like counts and groups survive, see ReadJSONBody), otherwise render a table.
type PostActionSpec ¶ added in v2.10.0
type PostActionSpec struct {
// Path is the fully built action path.
Path string
// Body is the optional JSON request body.
Body any
// FailureMessage wraps transport and status errors.
FailureMessage string
// SuccessMessage is the preformatted human-readable success line.
SuccessMessage string
// Timeout optionally extends the client timeout for slow actions.
Timeout time.Duration
// JSON prints the decoded response data instead of the success line.
JSON bool
}
PostActionSpec describes one resolve→POST→decode→report action command. T is the API envelope's data payload.
type ResourceRef ¶ added in v2.10.0
type ResourceRef[D any, S any] struct { // Singular and Plural name the resource in prompts and error messages // ("container", "containers"). Singular string Plural string // IDHint completes "use <IDHint> or run `<ListCmd>`" guidance // ("the container ID", "the volume name"). IDHint string ListCmd string // GetPath builds the GET-by-identifier path; ListPath the list endpoint // that Resolve queries with ?search=<identifier>&limit=-1. GetPath func(envID, identifier string) string ListPath func(envID string) string // SearchCandidates replaces the standard list search for resources with // specialized matching rules. SearchCandidates func(context.Context, *client.Client, string) ([]S, error) // SelectCandidate replaces the standard ambiguity handling while keeping // direct lookup and not-found behavior in Resolve. SelectCandidate func([]S, string, bool) (*S, error) // Validate checks a successful direct lookup before Resolve returns it. Validate func(D, string) error // Matches reports whether a listed item matches the identifier. Matches func(item S, identifierLower, original string) bool // Label renders one match as an interactive prompt option. Label func(S) string // Promote converts a selected summary into the detail shape. Promote func(S) *D // IDOf enables the last-resort ID-prefix scan over the full list for // resources addressed by opaque IDs (containers, images). Leave nil to // skip that fallback. IDOf func(S) string // Exact optionally reports an exact identifier match. When set and // exactly one search match is exact, it wins without prompting even if // broader substring matches exist. Exact func(item S, identifierLower, original string) bool }
ResourceRef describes how one resource kind is resolved from a name, ID, or prefix. D is the detail type returned by the GET-by-identifier endpoint and S the summary type returned by the list endpoint.
func (ResourceRef[D, S]) Resolve ¶ added in v2.10.0
func (ref ResourceRef[D, S]) Resolve(ctx context.Context, c *client.Client, identifier string, allowPrompt bool) (*D, bool, error)
Resolve finds one resource by exact identifier or search. The bool result reports whether the returned details are complete (fetched from the GET-by-identifier endpoint) rather than promoted from a list row.