cli

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultOperatorNetworkDir = "k8s/networks"

DefaultOperatorNetworkDir is the path to the operator network YAMLs. Resolved relative to the user's checkout of ~/work/operator.

Variables

This section is empty.

Functions

func AddNetworkFlags

func AddNetworkFlags(cmd *cobra.Command, nf *NetworkFlags)

AddNetworkFlags registers --mainnet, --testnet, --devnet, --dev on the given command's persistent flags so they propagate to all subcommands. Skips any flag already registered on the command (e.g. PocketBase's built-in --dev) so it's safe to call after app.RootCmd is constructed.

func BuildQuery

func BuildQuery(filter string, limit int, sort string, extra map[string]string) string

BuildQuery encodes query parameters for list endpoints.

func EnvURLs

func EnvURLs(env Env, serviceName string, localPort int) string

EnvURLs returns service URLs for the resolved environment.

func LoadToken

func LoadToken() string

LoadToken reads the stored token from disk. Returns empty string (no error) if the file does not exist.

func NewClusterCommand

func NewClusterCommand(nf *NetworkFlags) *cobra.Command

NewClusterCommand returns the `cluster` subcommand tree for managing Base HA groups. Uses the BASE_* env namespace per base-ha conventions.

func NewCollectionCommand

func NewCollectionCommand(clientFn func() *Client, formatFn func() Format) *cobra.Command

NewCollectionCommand returns the `collection` subcommand tree.

func NewConfigCommand

func NewConfigCommand() *cobra.Command

NewConfigCommand returns the `config` subcommand tree. Matches `lux config` shape.

func NewCronsCommand

func NewCronsCommand(clientFn func() *Client, formatFn func() Format) *cobra.Command

NewCronsCommand returns the `crons` subcommand tree.

func NewDaemonCommand

func NewDaemonCommand() *cobra.Command

NewDaemonCommand returns the `daemon` subcommand tree for managing the daemon process lifecycle. Works in two modes:

  • Local: spawns/kills the process directly (default when no --env flag).
  • K8s: delegates to kubectl for rollout management (when --env is set).

The daemon name is derived from os.Args[0] base name.

func NewLoginCommand

func NewLoginCommand(clientFn func() *Client, formatFn func() Format) *cobra.Command

NewLoginCommand returns the `login` subcommand.

func NewOperatorCommand

func NewOperatorCommand(nf *NetworkFlags) *cobra.Command

NewOperatorCommand returns the `operator` subcommand tree for managing Base K8s operator CRDs (liquid.network/v1alpha1).

func NewRPCCommand

func NewRPCCommand(clientFn func() *Client, formatFn func() Format) *cobra.Command

NewRPCCommand returns the `rpc` subcommand. Matches `lux rpc` shape: direct API call passthrough.

func NewRecordCommand

func NewRecordCommand(clientFn func() *Client, formatFn func() Format) *cobra.Command

NewRecordCommand returns the `record` subcommand tree.

func NewSelfCommand

func NewSelfCommand(version string) *cobra.Command

NewSelfCommand returns the `self` subcommand tree. Matches `lux self` shape: manages the binary install.

func NewStatusCommand

func NewStatusCommand(clientFn func() *Client, formatFn func() Format, nf *NetworkFlags) *cobra.Command

NewStatusCommand returns the `status` subcommand. Matches `lux status` shape: shows daemon health, leader info, etc.

func NewWhoamiCommand

func NewWhoamiCommand(clientFn func() *Client, formatFn func() Format) *cobra.Command

NewWhoamiCommand returns the `whoami` subcommand.

func Print

func Print(w io.Writer, format Format, data json.RawMessage) error

Print outputs data in the requested format to w.

func ResolveToken

func ResolveToken(flagToken string) string

ResolveToken returns the token from (in priority order): 1. --token flag 2. $BASE_TOKEN env var 3. ~/.config/base/token file

func ResolveURL

func ResolveURL(flagURL string) string

ResolveURL returns the server URL from (in priority order): 1. --url flag 2. $BASE_URL env var 3. http://127.0.0.1:8090

func SaveBaseConfig

func SaveBaseConfig(cfg *BaseConfig) error

SaveBaseConfig writes config.json.

func SaveToken

func SaveToken(token string) error

SaveToken writes the token to disk with mode 0600.

Types

type BaseConfig

type BaseConfig struct {
	DefaultEnv string               `json:"default_env"`
	Envs       map[string]EnvConfig `json:"envs"`
	DefaultOrg string               `json:"default_org"`
	TokenPath  string               `json:"token_path"`
}

BaseConfig is the ~/.config/base/config.json schema.

func LoadBaseConfig

func LoadBaseConfig() (*BaseConfig, error)

LoadBaseConfig reads config.json. Returns defaults if file is missing.

type Client

type Client struct {
	BaseURL   string
	Token     string
	Tenant    string
	APIPrefix string
	HTTP      *http.Client
}

Client is a thin HTTP client for the Base API.

func NewClient

func NewClient(baseURL, token, tenant string) *Client

NewClient returns a Client with sensible defaults.

func (*Client) Delete

func (c *Client) Delete(path string) (json.RawMessage, int, error)

Delete performs a DELETE request.

func (*Client) Do

func (c *Client) Do(method, path string, body any) (json.RawMessage, int, error)

Do executes a raw HTTP request against the Base API and returns the decoded JSON body. Non-2xx responses are returned as an error.

func (*Client) Get

func (c *Client) Get(path string) (json.RawMessage, int, error)

Get performs a GET request.

func (*Client) Patch

func (c *Client) Patch(path string, body any) (json.RawMessage, int, error)

Patch performs a PATCH request with a JSON body.

func (*Client) Post

func (c *Client) Post(path string, body any) (json.RawMessage, int, error)

Post performs a POST request with a JSON body.

type Env

type Env string

Env is a canonical environment name.

const (
	EnvMainnet Env = "mainnet"
	EnvTestnet Env = "testnet"
	EnvDevnet  Env = "devnet"
	EnvLocal   Env = "local"
)

func (Env) DomainSuffix

func (e Env) DomainSuffix() string

DomainSuffix returns the DNS zone suffix for service URLs.

func (Env) IsRemote

func (e Env) IsRemote() bool

IsRemote returns true when the resolved env targets a K8s cluster.

func (Env) K8sContext

func (e Env) K8sContext() string

K8sContext returns the GKE kubectl context for this env.

func (Env) K8sNamespace

func (e Env) K8sNamespace() string

K8sNamespace returns the K8s namespace for this env.

type EnvConfig

type EnvConfig struct {
	ATSURL string `json:"ats_url,omitempty"`
	BDURL  string `json:"bd_url,omitempty"`
	TAURL  string `json:"ta_url,omitempty"`
	IAMURL string `json:"iam_url,omitempty"`
}

EnvConfig holds per-environment service URLs.

type Format

type Format string

Format is the output format.

const (
	FormatTable Format = "table"
	FormatJSON  Format = "json"
	FormatYAML  Format = "yaml"
)

func DetectFormat

func DetectFormat(explicit string) Format

DetectFormat returns table if stdout is a TTY, json otherwise.

func ParseFormat

func ParseFormat(s string) Format

ParseFormat returns the output format from a string.

type NetworkFlags

type NetworkFlags struct {
	Mainnet bool
	Testnet bool
	Devnet  bool
	Dev     bool
}

NetworkFlags holds the mutually-exclusive --mainnet/--testnet/--devnet/--dev flags. Mirrors the lux/cli pattern: exactly one may be set.

func (*NetworkFlags) Resolve

func (nf *NetworkFlags) Resolve() (Env, error)

Resolve returns the canonical Env. Rules:

  1. Exactly one flag set -> that env.
  2. No flags -> $APP_ENV, then $BASE_ENV, then default "local".
  3. More than one flag -> error.

Jump to

Keyboard shortcuts

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