cli

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const LocalBrokerURL = "http://127.0.0.1:8080"

LocalBrokerURL is where `mercator serve` listens unless told otherwise, so it is also where the CLI looks when nothing else names a broker.

View Source
const LocalContextName = "local"

LocalContextName is the context `mercator serve` writes for a loopback broker whose token it generated itself.

Variables

This section is empty.

Functions

func DefaultConfigPath added in v0.3.0

func DefaultConfigPath(env map[string]string) string

DefaultConfigPath resolves where the CLI config lives: MERCATOR_CONFIG, else $XDG_CONFIG_HOME/mercator/config.json, else ~/.config/mercator/config.json.

func Run

func Run(ctx context.Context, cfg Config) int

func WriteLocalContext added in v0.5.0

func WriteLocalContext(configPath, apiURL, token string) (bool, error)

WriteLocalContext records how to reach a loopback broker the operator never configured a credential for, so the CLI on the same machine needs no exports to talk to the server they just started. It reports whether the file changed.

It only claims current_context when nothing else has: silently redirecting commands away from an operator's chosen deployment would be far worse than asking them to run `mercator context use local`.

Types

type Config

type Config struct {
	// BaseURL, Token, and WorkspaceID are the environment-derived values
	// (MERCATOR_API_URL / MERCATOR_API_TOKEN / MERCATOR_WORKSPACE_ID). They
	// win over the config file's current context, so CI setups keep working
	// with no config file at all.
	BaseURL string
	Token   string
	// WorkspaceID is the default workspace applied to run subcommands when
	// --workspace-id is not passed. An explicit --workspace-id flag always
	// overrides it.
	WorkspaceID string
	// ConfigPath is where named contexts live (see DefaultConfigPath).
	ConfigPath string
	Args       []string
	Stdin      io.Reader
	Stdout     io.Writer
	Stderr     io.Writer
	Client     *http.Client
	// OpenBrowser overrides how `mercator login` launches the browser
	// (injected in tests).
	OpenBrowser func(url string) error
}

type ContextConfig added in v0.3.0

type ContextConfig struct {
	APIURL      string `json:"api_url,omitempty"`
	WorkspaceID string `json:"workspace_id,omitempty"`
	APIToken    string `json:"api_token,omitempty"`

	CLIToken          string `json:"cli_token,omitempty"`
	CLITokenEmail     string `json:"cli_token_email,omitempty"`
	CLITokenExpiresAt string `json:"cli_token_expires_at,omitempty"`
}

ContextConfig names one Mercator deployment: where it is, the default workspace, and a credential — either a static API token or a login-minted CLI token tied to a user identity.

type FileConfig added in v0.3.0

type FileConfig struct {
	CurrentContext string                    `json:"current_context,omitempty"`
	Contexts       map[string]*ContextConfig `json:"contexts,omitempty"`
}

FileConfig is the on-disk CLI configuration: named contexts (a server plus how to talk to it) and which one is current. Environment variables always win over the file so CI keeps working unchanged.

Jump to

Keyboard shortcuts

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