Documentation
¶
Overview ¶
Package publish is `anfra publish`: a local repo's files published to its org, as PUBLISH.md (anfra-cloud) describes. The command wires it to the terminal (Env); its messages name the command's flags.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CheckResult ¶ added in v0.17.0
type CheckResult struct {
Message string `json:"message" doc:"the outcome, in a sentence"`
Org *OrgRef `json:"org" doc:"where it would be published; null when no org is configured"`
Files []string `json:"files" doc:"the files it would send" pretty:",tree"`
Hints []string `json:"hints,omitempty" doc:"what to do next; absent when nothing is"`
}
CheckResult is `publish check`'s result: what would be published, and where (docs/designs/commands-and-api.md#cli-output).
type Env ¶
type Env struct {
// ErrOut is where progress and questions go, for a person at a terminal.
ErrOut io.Writer
// Warn says a problem that doesn't stop the publish, by its code; nil says
// nothing.
Warn func(code, message string)
// OrgName is an org's name, as its login knows it; nil, or "": unknown.
OrgName func(cloudapi.Org) string
Ask Prompt
// Validate validates the repo here, before anything is sent: an error
// refusing the publish, carrying what fails. Always, and again on the
// server, whose verdict on exactly the published files is the one that
// publishes (PUBLISH.md §Decisions).
Validate func(context.Context) error
// Credential checks the selected login before destination configuration is
// saved, returning an authorizer that resolves credentials for every request.
Credential func(context.Context, cloudapi.Org) (func(*http.Request) error, error)
// SelectOrg explicitly selects a first destination; nil means no interactive terminal.
SelectOrg func(context.Context) (cloudapi.Org, error)
// RecoverOrg offers interactive recovery after credential loading fails.
// It must return the original error when recovery does not apply, and confirm
// any destination change before returning a different organization.
RecoverOrg func(context.Context, cloudapi.Org, error) (cloudapi.Org, error)
// UserAgent names the CLI and its version, for the server.
UserAgent string
// MotherDuck is the person's MotherDuck account, to copy a DuckDB data source
// to; nil offers no copy.
MotherDuck MotherDuck
// Input asks for a line of text, as Ask asks a question; nil with no
// terminal.
Input Input
}
Env is what a publish needs from the command around it.
type Input ¶ added in v0.13.0
Input asks for a line of text, and returns it trimmed: "" when nothing was typed, or the question was interrupted; ok is false when nobody can answer it.
type MotherDuck ¶ added in v0.13.0
type MotherDuck interface {
Find(ctx context.Context) (version string, ok bool)
Status(ctx context.Context) (motherduck.Status, error)
Login(ctx context.Context) error
Session(ctx context.Context) (token string, databases []string, err error)
DatabaseExists(ctx context.Context, name string) (bool, error)
CreateDatabaseFrom(ctx context.Context, name, path string) error
CreateReadToken(ctx context.Context, session, username, name, description string) (motherduck.Token, error)
RevokeToken(ctx context.Context, session, username, id string) error
}
MotherDuck is a person's MotherDuck account, as copying a DuckDB file there needs it (motherduck.Account). Nil offers no copy: without a terminal, nobody is there to sign in.
type Options ¶
type Options struct {
// Message is what the publish is, for the org's history of the repo; "" is
// HEAD's commit, in a git repo.
Message string
// SetOrg is an org's address to record as the repo's, and publish to.
SetOrg string
// Check is publish check: the preflight, which goes as far as a publish
// would before its first change, then says what it would do. Today, the
// part done here, offline, without authentication or config writes: the
// files, and where they'd go.
Check bool
// Yes publishes without asking, though the repo was last published elsewhere.
Yes bool
// CreateDataSources adds the data sources the repo uses and the org lacks
// without asking.
CreateDataSources bool
}
Options are a publish's choices: the command's flags.
type OrgRef ¶ added in v0.17.0
type OrgRef struct {
URL string `json:"url" doc:"the org's address"`
Name string `json:"name,omitempty" doc:"the org's name, as its login knows it; absent when unknown"`
}
OrgRef is an org a publish goes to: its address, and its name when the login knows it.
type Prompt ¶
Prompt asks a question with choices, the last one the default (the safe answer), and returns the choice's index; ok is false when nobody can answer it (not a terminal).
type Result ¶ added in v0.17.0
type Result struct {
Message string `json:"message" doc:"the outcome, in a sentence"`
Org OrgRef `json:"org" doc:"where it was published"`
Revision string `json:"revision" doc:"the revision published"`
Changed bool `json:"changed" doc:"false when these files were what the org had published"`
Replaced *cloudapi.Replaced `json:"replaced,omitempty" doc:"the revision it replaced; absent when none was published"`
Files int `json:"files" doc:"how many files it published"`
DataSourcesCreated []string `json:"data_sources_created" doc:"the data sources it added to the org"`
Hints []string `json:"hints,omitempty" doc:"what to do next; absent when nothing is"`
}
Result is a publish's result: the revision it published, and what came of it.