cli

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 26 Imported by: ? modules, 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

Index

Constants

View Source
const (
	InvocationTimeout = 30 * time.Second
	ConnectionTimeout = 10 * time.Second
	HelperTimeout     = 5 * time.Second
	StatementTimeout  = 10 * time.Second
	LockTimeout       = time.Second
	CleanupTimeout    = 2 * time.Second
	MaxHelperBytes    = 32 << 10
)
View Source
const (
	ExitSuccess     = 0
	ExitInput       = 2
	ExitUnavailable = 3
	ExitPolicy      = 4
	ExitDatabase    = 5
	ExitTimeout     = 6
	ExitResource    = 7
)
View Source
const (
	MaxInputBytes   = 1 << 20
	MaxOutputBytes  = 1 << 20
	MaxParameters   = 256
	MaxProfileBytes = 256
	DefaultRows     = 100
	MaxRows         = 1000
	MaxCellBytes    = 64 << 10
)

Variables

This section is empty.

Functions

func CleanupBudget

func CleanupBudget(ctx context.Context) time.Duration

CleanupBudget is fresh time reserved inside the invocation's outer deadline.

func CloseMachine

func CloseMachine(ctx context.Context, client *pg.MachineClient) error

func Dispatch

func Dispatch(parent context.Context, args []string, streams IO, registry map[string]Command) (bool, int)

Dispatch never enters the legacy application. The caller composes its registry.

func IsLegacyRoute

func IsLegacyRoute(args []string) bool

IsLegacyRoute recognizes valid legacy route words without admitting ignored positional command words into the TUI. The legacy app still validates values.

func LoadProfiles

func LoadProfiles(fs afero.Fs, path string) ([]models.Connection, error)

func ParseFlags

func ParseFlags(args []string, values, switches []string) (map[string]string, []string, error)

ParseFlags accepts exact long names and preserves positional names literally.

func ReadParameters

func ReadParameters(ctx context.Context, path string) ([][]byte, error)

func ReadSQL

func ReadSQL(ctx context.Context, path string, stdin io.ReadCloser) (string, error)

func ResolveExactProfile

func ResolveExactProfile(profiles []models.Connection, name string) (models.Connection, error)

func WriteJSON

func WriteJSON(ctx context.Context, out io.WriteCloser, envelope Envelope) error

WriteJSON owns publication until completion. Close on the injected writer must interrupt a blocked Write; non-cooperating writers are outside this contract.

Types

type ApprovalProvider added in v0.15.0

type ApprovalProvider func(context.Context, ApprovalRequest) error

func NewTerminalApprovalProvider added in v0.15.0

func NewTerminalApprovalProvider(open func(context.Context) (io.ReadWriteCloser, error)) ApprovalProvider

NewTerminalApprovalProvider takes ownership of each acquired handle. Close must interrupt and join concurrent I/O, as with the machineio stream contract.

type ApprovalRequest added in v0.15.0

type ApprovalRequest struct {
	Connection, SQL, Schema                     string
	MaxRows, ParameterCount, StatementCount     int
	WritesApprovalRequired, DDLApprovalRequired bool
}

ApprovalRequest is a captured invocation, without parameters or credentials.

type Command

type Command func(context.Context, []string, IO) (Envelope, error)

Command returns only after its backend operation and cleanup have completed.

func CapabilitiesCommand

func CapabilitiesCommand() Command

func ConnectionsCommand

func ConnectionsCommand(service InvocationService) Command

func LLMHelpCommand added in v0.15.0

func LLMHelpCommand() Command

LLMHelpCommand is static discovery: no service, files, stdin or credentials.

func QueryCommand

func QueryCommand(service InvocationService) Command

func SchemaCommand

func SchemaCommand(service InvocationService) Command

type Envelope

type Envelope struct {
	SchemaVersion    int                `json:"schema_version"`
	OK               bool               `json:"ok"`
	Command          string             `json:"command"`
	Connection       string             `json:"connection,omitempty"`
	Data             any                `json:"data,omitempty"`
	Error            *PublicError       `json:"error,omitempty"`
	Warnings         []ErrorCode        `json:"warnings"`
	ResultComplete   bool               `json:"result_complete"`
	Truncated        bool               `json:"truncated"`
	TruncationReason string             `json:"truncation_reason,omitempty"`
	Execution        *executionMetadata `json:"execution,omitempty"`
}

type ErrorCode

type ErrorCode string
const (
	InvalidInput              ErrorCode = "INVALID_INPUT"
	UnsupportedSQL            ErrorCode = "UNSUPPORTED_SQL"
	ConnectionUnavailable     ErrorCode = "CONNECTION_UNAVAILABLE"
	CredentialsUnavailable    ErrorCode = "CREDENTIALS_UNAVAILABLE"
	TrustRequired             ErrorCode = "TRUST_REQUIRED"
	UnsupportedPgpassFailover ErrorCode = "UNSUPPORTED_PGPASS_FAILOVER"
	PolicyDenied              ErrorCode = "POLICY_DENIED"
	ApprovalRequired          ErrorCode = "APPROVAL_REQUIRED"
	ApprovalMismatch          ErrorCode = "APPROVAL_MISMATCH"
	ApprovalUnavailable       ErrorCode = "APPROVAL_UNAVAILABLE"
	ApprovalCancelled         ErrorCode = "APPROVAL_CANCELLED"
	IncompleteTransaction     ErrorCode = "INCOMPLETE_TRANSACTION"
	DatabaseFailure           ErrorCode = "DATABASE_FAILURE"
	ObjectNotFound            ErrorCode = "OBJECT_NOT_FOUND"
	Timeout                   ErrorCode = "TIMEOUT"
	ResourceFailure           ErrorCode = "RESOURCE_FAILURE"
	HistoryUnavailable        ErrorCode = "HISTORY_UNAVAILABLE"
	HistoryUpgradeRequired    ErrorCode = "HISTORY_UPGRADE_REQUIRED"
)

type IO

type IO struct {
	In       io.ReadCloser
	Out, Err io.WriteCloser
	// Cancel interrupts operation/input work without prematurely closing output.
	Cancel <-chan struct{}
}

IO handles belong to one invocation. Close must interrupt concurrent I/O.

type InvocationService

type InvocationService struct {
	Load    func() ([]models.Connection, error)
	Options pg.MachineOptions
	Approve ApprovalProvider
	// contains filtered or unexported fields
}

func (InvocationService) Open

func (InvocationService) Profiles

func (s InvocationService) Profiles() ([]models.Connection, error)

type PublicError

type PublicError struct {
	Code     ErrorCode
	SQLState string
}

PublicError contains only allowlisted output, never backend error text.

func PublicMachineError

func PublicMachineError(err error) *PublicError

func (*PublicError) Error

func (e *PublicError) Error() string

func (*PublicError) MarshalJSON

func (e *PublicError) MarshalJSON() ([]byte, error)

type PublicProfile

type PublicProfile struct {
	Name             string           `json:"name"`
	Driver           string           `json:"driver"`
	Tags             []string         `json:"tags"`
	Label            string           `json:"label"`
	CLIAccess        models.CLIAccess `json:"cli_access"`
	ReadOnly         bool             `json:"read_only"`
	CredentialStatus string           `json:"credential_status"`
}

PublicProfile is an explicit allowlist, never a serialized connection config.

func PublicConnection

func PublicConnection(profile models.Connection) PublicProfile

Jump to

Keyboard shortcuts

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