core

package
v0.0.2-testing Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 17 Imported by: 1 module, 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 core is the contract between the CLI and product commands: the Product interface and the Factory that products receive.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProductEnv

func ProductEnv(p Product, suffix string) string

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

func (f *Factory) Account() (*auth.Resolved, error)

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

func (f *Factory) Auth() (*auth.Manager, error)

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

func (f *Factory) BaseURL(p Product) (string, error)

BaseURL resolves a product's API base URL: REEARTH_<PRODUCT>_BASE_URL > user env config > product default.

func (*Factory) Config

func (f *Factory) Config() (*config.Config, error)

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

func (f *Factory) Confirm(question string) error

Confirm asks for confirmation of a destructive action. --yes skips it; without a TTY it fails and asks for --yes.

func (*Factory) Env

func (f *Factory) Env() (*auth.Env, error)

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

func (f *Factory) FindProduct(name string) (Product, bool)

FindProduct looks up a registered product by name.

func (*Factory) HTTPClient

func (f *Factory) HTTPClient(ctx context.Context, p Product) (*http.Client, error)

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

func (f *Factory) OptionalProject() *config.Project

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) Printer

func (f *Factory) Printer() (*output.Printer, error)

Printer returns the output printer configured from global flags.

func (*Factory) Project

func (f *Factory) Project() (*config.Project, error)

Project returns the project file (.reearth.yaml) for the working directory, or nil.

func (*Factory) ProjectValue

func (f *Factory) ProjectValue(p Product, key, flagValue string) string

ProjectValue returns a product-scoped value: flag value > REEARTH_<PRODUCT>_<KEY> > .reearth.yaml.

func (*Factory) PublicHTTPClient

func (f *Factory) PublicHTTPClient() *http.Client

PublicHTTPClient returns a client without credentials, for public resources such as the documentation site.

func (*Factory) SetConfig

func (f *Factory) SetConfig(cfg *config.Config, m *auth.Manager)

SetConfig injects a config (for tests).

func (*Factory) Setting

func (f *Factory) Setting(key string) (string, config.Origin)

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).

Jump to

Keyboard shortcuts

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