progress

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package progress writes and reads the progress stream that a long-running ocfp command produces, one JSON object per line.

Index

Constants

View Source
const WireContract = 1

WireContract is the version of the progress stream format. A reader compares the header's wireContract with this value before it trusts the rest of the stream.

Variables

View Source
var (
	// ErrHeaderFirst is returned when Encode runs before Header.
	ErrHeaderFirst = errors.New("progress: the header must be written first")

	// ErrNoHeader is returned when a stream does not begin with a header record.
	ErrNoHeader = errors.New("progress: stream does not begin with a header record")
)
View Source
var ErrAnswerTooLong = errors.New("progress: answer line is too long")

ErrAnswerTooLong is returned when an answer line passes the length limit.

View Source
var ErrNoAnswerNonInteractive = errors.New("progress: question has no default and the run is not interactive")

ErrNoAnswerNonInteractive is returned when a run is not interactive and a question has no default, so nothing could answer it.

Functions

This section is empty.

Types

type AnswerSource added in v0.5.4

type AnswerSource interface {
	Answer(id string) (string, error)
}

AnswerSource supplies the answer for a question id, blocking until one is available.

type Artifact added in v0.5.4

type Artifact struct {
	Name   string `json:"name"`
	Path   string `json:"path"`
	Digest string `json:"digest"`
}

Artifact describes a file that a step produced.

type Clock

type Clock interface {
	Now() time.Time
}

Clock supplies the time stamped on each record.

func SystemClock

func SystemClock() Clock

SystemClock returns a Clock backed by the wall clock.

type Code

type Code string

Code is a stable, machine-readable name for a refusal or failure.

const (
	// CodeOwnerRecordMissing reports that the host has no owner record.
	CodeOwnerRecordMissing Code = "OWNER_RECORD_MISSING"

	// CodeOwnerMismatch reports a record that names another installation or
	// epoch.
	CodeOwnerMismatch Code = "OWNER_MISMATCH"

	// CodeRequestUnsigned reports a request that the owner's instance key did
	// not sign.
	CodeRequestUnsigned Code = "REQUEST_UNSIGNED"

	// CodeOwnerHandover reports an owner record that is in handover.
	CodeOwnerHandover Code = "OWNER_HANDOVER"

	// CodeJobRequestInvalid reports a request that does not parse or whose
	// issue time falls outside the accepted window.
	CodeJobRequestInvalid Code = "JOB_REQUEST_INVALID"

	// CodeVerbNotAllowed reports a verb that the wrapper does not accept.
	CodeVerbNotAllowed Code = "VERB_NOT_ALLOWED"

	// CodeWireContractUnsupported reports a wire contract version that the
	// CLI cannot write.
	CodeWireContractUnsupported Code = "WIRE_CONTRACT_UNSUPPORTED"

	// CodeOwnerRecordExists reports a create-only write of an owner record
	// where one already exists.
	CodeOwnerRecordExists Code = "OWNER_RECORD_EXISTS"

	// CodeJobOrphaned reports an attach to a spool whose wrapper died without
	// writing an exit record.
	CodeJobOrphaned Code = "JOB_ORPHANED"
)

The refusal codes. A code is never renamed once it ships.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder reads records from a stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a Decoder that reads from r.

func (*Decoder) Decode

func (d *Decoder) Decode() (Record, error)

Decode returns the next record after the header. When the header has not been read yet, Decode reads and checks it first, so a stream without a header is refused with ErrNoHeader. At the end of the stream it returns io.EOF.

func (*Decoder) Header

func (d *Decoder) Header() (Header, error)

Header reads the first record and returns its header body. It returns ErrNoHeader when the stream is empty or begins with another kind of record.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder writes records as lines of JSON. It is safe for concurrent use, and a line is always written whole.

func NewEncoder

func NewEncoder(w io.Writer, c Clock) *Encoder

NewEncoder returns an Encoder that writes to w and stamps records from c.

func (*Encoder) Encode

func (e *Encoder) Encode(kind Kind, body any) error

Encode writes one record of the given kind. It returns ErrHeaderFirst until Header has been called.

func (*Encoder) Header

func (e *Encoder) Header(h Header) error

Header writes the header record, which carries seq 0. The WireContract field is always set to the current WireContract.

type ErrorBody

type ErrorBody struct {
	Code    Code   `json:"code"`
	Message string `json:"message"`
}

ErrorBody is the body of an error record.

type Event added in v0.5.4

type Event struct {
	Kind     EventKind `json:"kind"`
	Step     string    `json:"step"`
	Message  string    `json:"message,omitempty"`
	Current  int64     `json:"current,omitempty"`
	Total    int64     `json:"total,omitempty"`
	Outcome  string    `json:"outcome,omitempty"`
	Artifact *Artifact `json:"artifact,omitempty"`
}

Event is one structured report of progress from a step.

type EventKind added in v0.5.4

type EventKind string

EventKind names the type of a progress event.

const (
	EventStepStarted      EventKind = "step_started"
	EventStepProgress     EventKind = "step_progress"
	EventStepFinished     EventKind = "step_finished"
	EventWarning          EventKind = "warning"
	EventArtifactProduced EventKind = "artifact_produced"
)

The event kinds.

type Header struct {
	WireContract int    `json:"wireContract"`
	Producer     string `json:"producer"`
	Version      string `json:"version"`
	JobID        string `json:"jobId,omitempty"`
}

Header is the body of the first record. It names the producer and the wire contract the rest of the stream follows.

type Kind

type Kind string

Kind names the type of a record in the stream.

const (
	KindHeader   Kind = "header"
	KindEvent    Kind = "event"
	KindQuestion Kind = "question"
	KindLog      Kind = "log"
	KindResult   Kind = "result"
	KindError    Kind = "error"
)

The record kinds. The first record of every stream is a header.

type LogBody

type LogBody struct {
	Stream string `json:"stream"`
	Line   string `json:"line"`
}

LogBody is the body of a log record.

type Prompter added in v0.5.4

type Prompter interface {
	Ask(q Question) (string, error)
}

Prompter asks a question and returns the answer.

func NewNDJSONPrompter added in v0.5.4

func NewNDJSONPrompter(enc *Encoder, src AnswerSource, interactive bool) Prompter

NewNDJSONPrompter returns a Prompter that writes each question as a question record and then waits for src to supply the answer. An answer is never written to the stream. When interactive is false it answers from the default without writing anything, and fails when there is none.

func NewTerminalPrompter added in v0.5.4

func NewTerminalPrompter(in io.Reader, out io.Writer, interactive bool) Prompter

NewTerminalPrompter returns a Prompter that writes questions to out and reads answers from in. When interactive is false it never touches either, answers from the default, and fails when there is none. A sensitive question's default is never printed. The reader is used as given, so a caller that wants hidden input passes a reader that provides it. A terminal prompter is for one goroutine at a time.

type Question added in v0.5.4

type Question struct {
	ID        string       `json:"id"`
	Kind      QuestionKind `json:"kind"`
	Text      string       `json:"text"`
	Choices   []string     `json:"choices"`
	Default   *string      `json:"default"`
	Sensitive bool         `json:"sensitive"`
}

Question is one thing a step needs answered. A confirm answer is "yes" or "no", and a choose answer is one of Choices. Default is nil when the question has none.

type QuestionKind added in v0.5.4

type QuestionKind string

QuestionKind names the shape of the answer a question expects.

const (
	QuestionConfirm QuestionKind = "confirm"
	QuestionChoose  QuestionKind = "choose"
	QuestionText    QuestionKind = "text"
)

The question kinds.

type Record

type Record struct {
	Kind Kind            `json:"kind"`
	Seq  int64           `json:"seq"`
	Time time.Time       `json:"time"`
	Body json.RawMessage `json:"body"`
}

Record is one line of the stream. Seq is 0 for the header and counts up by one for every record after it.

type Refusal added in v0.5.4

type Refusal struct {
	Code    Code
	Message string
}

Refusal is an error that carries a Code, so a caller can act on the reason without matching message text.

func AsRefusal added in v0.5.4

func AsRefusal(err error) (*Refusal, bool)

AsRefusal finds a *Refusal anywhere in err's chain.

func (*Refusal) Error added in v0.5.4

func (r *Refusal) Error() string

Error returns the code followed by the message.

type ResultBody

type ResultBody struct {
	ExitCode int `json:"exitCode"`
}

ResultBody is the body of the final record of a stream.

type Sink added in v0.5.4

type Sink interface {
	Emit(ev Event) error
}

Sink receives progress events. An adapter decides how to show them.

func NewNDJSONSink added in v0.5.4

func NewNDJSONSink(enc *Encoder) Sink

NewNDJSONSink returns a Sink that writes each event as an event record.

func NewTerminalSink added in v0.5.4

func NewTerminalSink(w io.Writer) Sink

NewTerminalSink returns a Sink that prints events as readable lines to w.

Directories

Path Synopsis
Package progresstest holds golden progress streams for tests.
Package progresstest holds golden progress streams for tests.

Jump to

Keyboard shortcuts

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