Documentation
¶
Overview ¶
Package core is the contract between the CLI and product commands: the Product interface and the Factory that products receive.
Index ¶
- func ProductEnv(p Product, suffix string) string
- type APIProduct
- type Check
- type CheckStatus
- type Factory
- func (f *Factory) Account() (*auth.Resolved, error)
- func (f *Factory) Auth() (*auth.Manager, error)
- func (f *Factory) BaseURL(p Product) (string, error)
- func (f *Factory) Config() (*config.Config, error)
- func (f *Factory) Confirm(question string) error
- func (f *Factory) Env() (*auth.Env, error)
- func (f *Factory) FindProduct(name string) (Product, bool)
- func (f *Factory) HTTPClient(ctx context.Context, p Product) (*http.Client, error)
- func (f *Factory) OptionalProject() *config.Project
- func (f *Factory) Printer() (*output.Printer, error)
- func (f *Factory) Project() (*config.Project, error)
- func (f *Factory) ProjectValue(p Product, key, flagValue string) string
- func (f *Factory) PublicHTTPClient() *http.Client
- func (f *Factory) SetConfig(cfg *config.Config, m *auth.Manager)
- func (f *Factory) Setting(key string) (string, config.Origin)
- type GlobalFlags
- type Product
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ProductEnv ¶
ProductEnv returns REEARTH_<PRODUCT>_<SUFFIX>.
Types ¶
type APIProduct ¶
type APIProduct interface {
Product
// BaseURL returns the API base URL for an environment ("" if unknown).
BaseURL(env *auth.Env) string
}
APIProduct is implemented by products that call an HTTP API.
type Check ¶
type Check struct {
Name string `json:"name"`
Status CheckStatus `json:"status"`
Detail string `json:"detail"`
Hint string `json:"hint,omitempty"`
}
Check is one line of `doctor` output.
type CheckStatus ¶
type CheckStatus string
const ( CheckOK CheckStatus = "ok" CheckWarn CheckStatus = "warn" CheckFail CheckStatus = "fail" )
type Factory ¶
type Factory struct {
// AppName is the binary name used in help and hints ("reearth", "reearth-cms").
AppName string
IO *iostreams.IOStreams
Prompter prompt.Prompter
Flags *GlobalFlags
Products []Product
// OpenBrowser opens a URL (overridable for tests).
OpenBrowser func(url string) error
// DoctorChecks are extra checks for `doctor` contributed by the host binary.
DoctorChecks []func(ctx context.Context) []Check
// contains filtered or unexported fields
}
Factory gives commands lazy access to shared services.
func (*Factory) Account ¶
Account resolves the account for this invocation. REEARTH_TOKEN needs no config file, so a broken one is then only warned about.
func (*Factory) Auth ¶
Auth returns the account manager, for core commands that manage accounts and credentials. Products must not call it: the manager hands out token strings. Products use HTTPClient.
func (*Factory) BaseURL ¶
BaseURL resolves a product's API base URL: REEARTH_<PRODUCT>_BASE_URL > user env config > product default.
func (*Factory) Config ¶
Config returns the loaded user config. When the file cannot be loaded, the error names it and says how to fix it.
func (*Factory) Confirm ¶
Confirm asks for confirmation of a destructive action. --yes skips it; without a TTY it fails and asks for --yes.
func (*Factory) Env ¶
Env returns the auth environment of the resolved account (prod if none). A broken config file fails it unless the account comes from REEARTH_TOKEN.
func (*Factory) FindProduct ¶
FindProduct looks up a registered product by name.
func (*Factory) HTTPClient ¶
HTTPClient returns an authenticated client for a product. Tokens are attached and refreshed transparently; products never see token strings. REEARTH_<PRODUCT>_TOKEN, if set, is used as a static token for that product.
func (*Factory) OptionalProject ¶
OptionalProject returns the project file, or nil when there is none or it cannot be loaded. A load error is printed once as a warning.
func (*Factory) Project ¶
Project returns the project file (.reearth.yaml) for the working directory, or nil.
func (*Factory) ProjectValue ¶
ProjectValue returns a product-scoped value: flag value > REEARTH_<PRODUCT>_<KEY> > .reearth.yaml.
func (*Factory) PublicHTTPClient ¶
PublicHTTPClient returns a client without credentials, for public resources such as the documentation site.
func (*Factory) Setting ¶
Setting resolves a setting (see config.Config.Get). When the config file cannot be loaded, it resolves from the environment and the defaults, so that commands which do not need the file still run. Their warning about the file waits until the command shows it runs without it, by creating a Printer or using a token from the environment, so that a command that fails on the file reports only the load error. A command that reports the error itself, like doctor, calls Config first, which suppresses the warning.
type GlobalFlags ¶
type GlobalFlags struct {
Account string
Output output.Options
Yes bool
NoInput bool
NoColor bool
Quiet bool
Debug bool
}
GlobalFlags are the persistent flags shared by every command.
type Product ¶
type Product interface {
// Name is the subcommand name, e.g. "cms".
Name() string
// Short is a one-line description.
Short() string
// Command builds the product's command tree.
Command(f *Factory) *cobra.Command
}
Product is a Re:Earth product CLI (viz, cms, flow, ...). The same Product runs standalone (reearth-cms) or as a subcommand (reearth cms).