resource

package
v6.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package resource holds what the commands managing schedules, services, profiles, templates and runs share: writing a document to a file or stdout, reading one back, and applying files with the new id written into them.

Index

Constants

View Source
const ListTypeHelp = `Print the platform's items as "json" or "yaml" instead of a table.`

ListTypeHelp describes the -t flag of listings.

Variables

This section is empty.

Functions

func ApplyFiles

func ApplyFiles(paths []string, recursive bool, what string, upsert func(file string, doc *output.Document) (Applied, error)) error

ApplyFiles upserts every file. A file without an id gets the new one written into it, first, so the next apply updates what this one created instead of creating another.

func Body

func Body(value any) io.Reader

Body sends a document or value as the JSON the platform expects.

func Confirmed

func Confirmed(yes bool, question string) (bool, error)

Confirmed asks before something that cannot be undone, unless --yes was given. Without a terminal, as in a pipeline, it goes ahead, as `experiment run` does.

func CreatedOrUpdated

func CreatedOrUpdated(created bool) string

func DecodeEach

func DecodeEach[T any](raw []json.RawMessage, into *[]T) error

DecodeEach decodes raw items into typed ones, for the table.

func DecodeListed

func DecodeListed(resp *http.Response, err error, field string, typed any) ([]json.RawMessage, error)

DecodeListed reads a listing response once: into typed, for the table, and as the raw items under field ("" for a response that is the array itself), for -t and --jq.

func List

func List(items []json.RawMessage, explicitType string, table func() error) error

List prints items, the platform's objects as it sent them, as JSON or YAML, or hands over to table when a person is reading.

func Machine

func Machine(explicitType string) bool

Machine reports whether a listing prints its items rather than a table: with -t, or when --jq filters them.

func Optional

func Optional(values []string) *[]string

Optional leaves an empty filter out of the request.

func Output

func Output(doc *output.Document, file, explicitType string) error

Output writes to the file when one is given and to stdout otherwise, as JSON indented by two, or YAML.

func OutputValue

func OutputValue(value *jsyaml.Map, file, explicitType string) error

OutputValue is Output for a value that is not an object, such as a map of variables.

func PrintJSONValue

func PrintJSONValue(raw []byte, explicitType string) error

PrintJSONValue prints any JSON value as -t and --jq ask: through the jq expression, or as YAML, or as indented JSON.

func Read

func Read(file, what string) (*output.Document, output.Datatype, error)

Read loads a JSON or YAML file; JSON is tried first, as it was.

func Strip

func Strip(doc *output.Document, fields ...string) *output.Document

Strip removes fields the platform reports but does not accept back, so that a file written by `get` can be applied again unchanged.

func Time

func Time(flag, value string) (*time.Time, error)

Time takes a date, meaning its start in UTC, or a full RFC 3339 time.

func UUID

func UUID(id string) (openapi_types.UUID, bool)

UUID parses an id; a malformed one cannot name anything, so callers report it as not found.

func Variables

func Variables(pairs []string, file string, replace bool) (*jsyaml.Map, error)

Variables merges KEY=VALUE arguments, always strings, over a file's variables, which may be lists or select expressions. Nothing given is only allowed when replacing, where it removes every variable.

func VariablesOutcome

func VariablesOutcome(replace bool) string

Types

type Applied

type Applied struct {
	ID      string
	Created bool
}

Jump to

Keyboard shortcuts

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