zcontext

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MPL-2.0 Imports: 1 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 zcontext is used to store the context information for the application.

Index

Constants

View Source
const (
	KeyContext = "context"

	// Workspace lives at the top level (sibling to context), mirroring its
	// role as an outer scope: a workspace switch invalidates the inner
	// project / environment / service context.
	KeyWorkspace     = "workspace"
	KeyWorkspaceID   = KeyWorkspace + ".id"
	KeyWorkspaceName = KeyWorkspace + ".name"
	KeyWorkspaceKind = KeyWorkspace + ".kind"

	KeyProject     = KeyContext + ".project"
	KeyProjectID   = KeyProject + ".id"
	KeyProjectName = KeyProject + ".name"

	KeyEnvironment     = KeyContext + ".environment"
	KeyEnvironmentID   = KeyEnvironment + ".id"
	KeyEnvironmentName = KeyEnvironment + ".name"

	KeyService     = KeyContext + ".service"
	KeyServiceID   = KeyService + ".id"
	KeyServiceName = KeyService + ".name"
)

Keys for context

View Source
const WorkspaceKindTeam = "team"

WorkspaceKindTeam marks a workspace as a Zeabur team. The empty string is "personal" — the user's own resources, the default when the CLI has never been switched to a team.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicInfo

type BasicInfo interface {
	GetID() string
	GetName() string
	Empty() bool
}

BasicInfo represents the basic information of a resource.

func NewBasicInfo

func NewBasicInfo(id, name string) BasicInfo

type Context

type Context interface {
	// GetWorkspace returns the persisted workspace. Always non-nil; check
	// IsPersonal() / IsTeam() to branch. Personal is the zero value.
	GetWorkspace() *Workspace
	// SetWorkspace persists the workspace; passing nil is equivalent to
	// ClearWorkspace().
	SetWorkspace(workspace *Workspace)
	// ClearWorkspace returns to personal — the default zero state.
	ClearWorkspace()

	GetProject() BasicInfo
	SetProject(project BasicInfo)
	ClearProject()

	GetEnvironment() BasicInfo
	SetEnvironment(environment BasicInfo)
	ClearEnvironment()

	GetService() BasicInfo
	SetService(service BasicInfo)
	ClearService()

	// ClearAll clears the inner project / environment / service context but
	// leaves the workspace intact. Use ClearWorkspace() to go back to personal,
	// which on its own does not touch the inner context — switching commands
	// orchestrate that explicitly so they can report what was cleared.
	ClearAll()
}

Context represents the current context of the CLI, including the current workspace (personal or team), and the pinned project / environment / service inside that workspace.

func NewEphemeralContext added in v0.18.0

func NewEphemeralContext(workspace *Workspace) Context

NewEphemeralContext returns a new in-memory Context whose GetWorkspace() reports the supplied workspace. Pass `nil` for personal (or when no override is active and the caller really wants a blank scratch context — uncommon).

func NewViperContext

func NewViperContext(viper *viper.Viper) Context

NewViperContext creates a new Context based on viper

type Workspace added in v0.18.0

type Workspace struct {
	// ID is the team's MongoDB ObjectID hex string. Empty for personal.
	ID string
	// Name is the team's display name. Empty for personal.
	Name string
	// Kind is "team" for team workspaces, empty for personal.
	Kind string
}

Workspace identifies which owner the CLI is currently acting against for directory-level commands (project list, project create, deploy with no linked project). Other commands address resources by their own ID and stay workspace-independent.

func (*Workspace) IsPersonal added in v0.18.0

func (w *Workspace) IsPersonal() bool

IsPersonal reports whether the workspace addresses the caller's own resources (no team scope). The zero value is personal.

func (*Workspace) IsTeam added in v0.18.0

func (w *Workspace) IsTeam() bool

IsTeam reports whether the workspace addresses a team.

Jump to

Keyboard shortcuts

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