cli

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

Package cli implements the diverge command-line interface, providing commands for creating, listing, deleting, and managing preview environments.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTailscaleNotFound indicates that no suitable local network interface could be found during detector fallback.
	ErrTailscaleNotFound = errors.New("tailscale interface not found: make sure tailscale is running or pass --endpoint")
	// ErrNoGitRepo indicates that the detector failed to find a git repository in the current directory.
	ErrNoGitRepo = errors.New("not in a git repository")
)
View Source
var ErrBaselinePodNotFound = errors.New("no baseline pod found")

ErrBaselinePodNotFound is returned when no baseline pod can be found for the given service name and namespace.

View Source
var ErrCollision = errors.New("preview group collision")

ErrCollision indicates that a preview group with the same name already exists but belongs to a different owner.

View Source
var ErrInvalidServiceName = errors.New("invalid service name")

ErrInvalidServiceName is returned when the service name is not a valid Kubernetes label value.

Functions

func Execute

func Execute(version, commit, date string)

Execute is the main entry point for the diverge CLI. It injects version metadata into the App, initializes the root command if needed, and runs it.

func NewRootCmd

func NewRootCmd(app *App) *cobra.Command

NewRootCmd constructs the root cobra.Command with persistent flags for kubeconfig, namespace, and context, and registers all subcommands (create, delete, init, list, logs, open, status, validate, version).

func RootCmd

func RootCmd() *cobra.Command

RootCmd returns the root cobra command. External modules (e.g., diverge-enterprise) use this to add enterprise subcommands.

Types

type App

type App struct {
	Kubeconfig string
	Namespace  string
	Context    string
	NoColor    bool
	Version    string
	Commit     string
	Date       string

	Client    client.Client        // For testing
	Clientset kubernetes.Interface // For testing (logs needs CoreV1)
}

App holds shared CLI state including Kubernetes connection details, version metadata, and optional API clients supplied by tests.

func (*App) KubeClient

func (app *App) KubeClient() (client.Client, kubernetes.Interface, error)

KubeClient returns a controller-runtime client and a kubernetes.Clientset. It returns injected clients when app.Client is non-nil; otherwise it creates both clients from kubeconfig.

func (*App) ResolveNamespace

func (app *App) ResolveNamespace() error

ResolveNamespace resolves the namespace from the kubeconfig if not explicitly set via --namespace flag.

type DefaultEnvironmentDetector

type DefaultEnvironmentDetector struct{}

DefaultEnvironmentDetector provides actual OS/network detection implementations.

func (*DefaultEnvironmentDetector) DetectGitBranch

func (d *DefaultEnvironmentDetector) DetectGitBranch(ctx context.Context) (string, error)

DetectGitBranch performs its designated operation.

func (*DefaultEnvironmentDetector) DetectLocalIP

func (d *DefaultEnvironmentDetector) DetectLocalIP(ctx context.Context) (string, error)

DetectLocalIP performs its designated operation.

func (*DefaultEnvironmentDetector) DetectServiceName

func (d *DefaultEnvironmentDetector) DetectServiceName(ctx context.Context) (string, error)

DetectServiceName performs its designated operation.

func (*DefaultEnvironmentDetector) DetectUsername

func (d *DefaultEnvironmentDetector) DetectUsername(ctx context.Context) (string, error)

DetectUsername performs its designated operation.

type DevOption

type DevOption func(*DevOptions)

DevOption configures DevOptions (e.g. WithDetector, WithPort, WithService).

func WithEnvironmentDetector

func WithEnvironmentDetector(d EnvironmentDetector) DevOption

WithEnvironmentDetector allows injecting a custom EnvironmentDetector for testing.

type DevOptions

type DevOptions struct {
	Detector EnvironmentDetector
	// contains filtered or unexported fields
}

DevOptions holds optional configuration for the dev command.

type EnvironmentDetector

type EnvironmentDetector interface {
	// DetectLocalIP returns the developer's routable IP (e.g., Tailscale).
	DetectLocalIP(ctx context.Context) (string, error)

	// DetectGitBranch returns the current git branch name.
	DetectGitBranch(ctx context.Context) (string, error)

	// DetectServiceName returns the service name from .diverge.yaml or cwd.
	DetectServiceName(ctx context.Context) (string, error)

	// DetectUsername returns the current OS username.
	DetectUsername(ctx context.Context) (string, error)
}

EnvironmentDetector abstracts OS/network dependencies for testability.

Jump to

Keyboard shortcuts

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