Documentation
¶
Overview ¶
Package progress writes and reads the progress stream that a long-running ocfp command produces, one JSON object per line.
Index ¶
Constants ¶
const WireContract = 2
WireContract is the version of the progress stream format and of the job request that asks for it. A reader compares the header's wireContract with this value before it trusts the rest of the stream. Contract 2 added the org and the bloc to the job request.
Variables ¶
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") )
var ErrAnswerTooLong = errors.New("progress: answer line is too long")
ErrAnswerTooLong is returned when an answer line passes the length limit.
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
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 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" // CodeOwnerRecordInvalid reports an owner record on the host that does // not parse or does not verify, so that a requester never reads it as a // fault in its own request. CodeOwnerRecordInvalid Code = "OWNER_RECORD_INVALID" // CodeOrgBlocMismatch reports a request, a replacement owner record, or a // proof that gives up the owner record, for an org or a bloc other than // the one the host's owner record names. CodeOrgBlocMismatch Code = "ORG_BLOC_MISMATCH" )
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 ¶
NewDecoder returns a Decoder that reads from r.
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 ¶
NewEncoder returns an Encoder that writes to w and stamps records from c.
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.
type Header ¶
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 Prompter ¶ added in v0.5.4
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
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
Refusal is an error that carries a Code, so a caller can act on the reason without matching message text.
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
Sink receives progress events. An adapter decides how to show them.
func NewNDJSONSink ¶ added in v0.5.4
NewNDJSONSink returns a Sink that writes each event as an event record.
func NewTerminalSink ¶ added in v0.5.4
NewTerminalSink returns a Sink that prints events as readable lines to w.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package progresstest holds golden progress streams for tests.
|
Package progresstest holds golden progress streams for tests. |