resource

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package resource defines the core abstraction every browsable Databricks resource implements. The UI renders any ResourceDef through one generic browser view; the registry maps `:` commands to defs. This package never imports the Databricks SDK — concrete defs live in internal/resources and reach the API through the narrow DAO interfaces in internal/dbx.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Key  string // e.g. "l"
	Name string // shown in header hints, e.g. "Logs"
	// Dangerous actions require a confirmation dialog and are hidden
	// entirely when the app runs with --readonly.
	Dangerous bool
	// NeedsRow actions are no-ops when the table is empty.
	NeedsRow bool
	// Run performs the action. It executes inside a tea.Cmd, so it may do
	// I/O; it returns a message for the app to route (declared as any here
	// to keep this package free of UI imports).
	Run func(ctx context.Context, c *dbx.Clients, scope Scope, row Row) any
}

Action is a verb key available on a resource view beyond the universal Enter/Esc/describe bindings.

type AltWebLinker

type AltWebLinker interface {
	AltWebURL(host string, scope Scope, row Row) (url string, ok bool)
	AltWebHint() string
}

AltWebLinker is optionally implemented by defs that have a second, distinct web target beyond WebLinker's primary one — the browser binds `O` to it. For apps, `o` (WebLinker) opens the workspace management page while `O` opens the deployed app itself. AltWebHint is the short verb shown in the key help (e.g. "open app"); AltWebURL returns ok=false when the row has no such link.

type CellClass

type CellClass int

CellClass is a semantic classification of a rendered cell value, mapped to theme styles by the table component (defs know values, not colors).

const (
	CellDefault CellClass = iota
	CellGood              // e.g. SUCCESS, RUNNING pipeline in healthy state
	CellBad               // e.g. FAILED, INTERNAL_ERROR
	CellWarn              // e.g. CANCELED, TIMEDOUT, SKIPPED
	CellRunning           // e.g. RUNNING, PENDING — in-flight states
)

Cell classes.

type ColSpec

type ColSpec[T any] struct {
	Column
	Extract func(T) string
}

ColSpec pairs a column definition with a typed cell extractor. Concrete defs declare a []ColSpec[T] once; Cols and BuildRows derive everything else, keeping type assertions out of view code entirely.

type Column

type Column struct {
	Title string
	// Width semantics: 0 = flex (share remaining space), >0 = fixed width.
	Width int
	// Wide columns are hidden unless the terminal is wide enough.
	Wide bool
}

Column describes one table column.

func Cols

func Cols[T any](specs []ColSpec[T]) []Column

Cols projects the Column definitions out of a spec list.

type Command

type Command struct {
	Def   Def
	Scope Scope
	// Filter pre-seeds a substring filter on the list, from a trailing /text.
	Filter string
	// Item is a positional item selector beyond the scope args — the exact
	// name (or ID) of a single row to open directly, e.g. the "orders" in
	// `tables main silver orders` or the "my-app" in `apps my-app`.
	Item string
}

Command is a parsed `:` command line.

type Def

type Def interface {
	// Name is the canonical command name, e.g. "tables".
	Name() string
	// Aliases are alternative command names, e.g. ["table", "tbl"].
	Aliases() []string
	// Args names the positional scope keys required by this resource, in
	// order, e.g. tables → ["catalog", "schema"]. Empty for unscoped.
	Args() []string
	Columns() []Column
	List(ctx context.Context, c *dbx.Clients, scope Scope) ([]Row, error)
	// PollInterval is the steady-state refresh cadence; the engine adds
	// jitter and backoff. Use long intervals for rate-limited APIs (SCIM).
	PollInterval() time.Duration
	// Child names the resource pushed when the user presses Enter on a
	// row; "" marks a leaf.
	Child() string
	// ChildScope builds the drilled-down scope from the selected row.
	ChildScope(parent Scope, row Row) Scope
	Actions() []Action
	// Describe returns the detail object rendered by the describe view.
	Describe(ctx context.Context, c *dbx.Clients, scope Scope, row Row) (any, error)
}

Def is the interface every browsable resource implements.

type Opener

type Opener interface {
	EnterMsg(c *dbx.Clients, scope Scope, row Row) any
}

Opener is optionally implemented by defs whose Enter opens a richer view than the default child drill-down (e.g. tables open a tabbed detail). EnterMsg returns the message the browser emits; it overrides Child(). Like Action.Run, it receives clients so it can bind fetch closures.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry resolves command names and aliases to resource defs.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty registry.

func (*Registry) Canonical

func (r *Registry) Canonical() []string

Canonical returns only the canonical resource names, sorted — shown when the command bar opens empty, so every resource is discoverable.

func (*Registry) Complete

func (r *Registry) Complete(prefix string) []string

Complete returns registered names with the given prefix, for autocomplete.

func (*Registry) Get

func (r *Registry) Get(nameOrAlias string) (Def, bool)

Get resolves a name or alias; ok is false when unknown.

func (*Registry) MustRegister

func (r *Registry) MustRegister(d Def)

MustRegister adds a def, panicking on name/alias collisions — collisions are programmer error and should fail at startup, loudly.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns all canonical names plus aliases, sorted — the completion source for the command bar.

func (*Registry) Parse

func (r *Registry) Parse(input string) (Command, error)

Parse interprets a command string; see ParseArgs for the grammar. Fields are split on whitespace — callers with already-tokenized args (which preserve quoted names containing spaces) should use ParseArgs directly.

func (*Registry) ParseArgs

func (r *Registry) ParseArgs(fields []string) (Command, error)

ParseArgs interprets pre-tokenized command args like:

tables main silver           # list a schema's tables
tables main.silver           # dotted sugar for the scope
tables main silver orders    # open the 'orders' table directly
tables main silver /events   # list, pre-filtered to 'events'
apps my-app                  # open 'my-app' directly

The first field names the resource. Following positionals map onto Def.Args(); a leading dotted arg is sugar for the scope list. One positional beyond the scope args is the Item selector (the row to open). A trailing /text pre-seeds the list filter instead.

func (*Registry) Summaries

func (r *Registry) Summaries() []string

Summaries renders one line per resource — "name (alias1, alias2) [args]" — for the help view.

type Row

type Row struct {
	ID    string   // stable identity: cursor preservation, drill-down key
	Cells []string // aligned to Columns()
	Data  any
}

Row is one pre-rendered table row. Data retains the original API object; it is only ever type-asserted back inside the def that created the row.

func BuildRows

func BuildRows[T any](items []T, id func(T) string, specs []ColSpec[T]) []Row

BuildRows renders API objects into rows using the given specs.

func (Row) MatchesFilter

func (r Row) MatchesFilter(filter string) bool

MatchesFilter reports whether any cell contains the filter text (case-insensitive substring). An empty filter matches everything.

type RowNamer

type RowNamer interface {
	RowName(row Row) string
}

RowNamer is optionally implemented by defs whose rows carry a human name distinct from Row.ID (e.g. jobs: Row.ID is the numeric job id, but the CLI refers to jobs by name). The name is offered as the shell-completion candidate and accepted as a launch Item selector alongside the ID. It must read from Row.Cells (not Row.Data), so it also works on rows restored from the on-disk cache, whose Data is a generic map.

type Scope

type Scope map[string]string

Scope parameterizes a view, e.g. {"catalog": "main", "schema": "silver"} for a tables view or {"job_id": "123"} for a runs view.

func (Scope) Hash

func (s Scope) Hash() string

Hash returns a stable string form of the scope, used in cache keys.

func (Scope) Merge

func (s Scope) Merge(key, value string) Scope

Merge returns a copy of s with an extra key set. The receiver is not modified, so parent scopes are safe to share across drill-downs.

type Styler

type Styler interface {
	CellClass(col int, value string) CellClass
}

Styler is optionally implemented by defs whose cells deserve semantic coloring (run states, health columns). col indexes into Columns().

type Tabber

type Tabber interface {
	Tabs() []string
}

Tabber is optionally implemented by Opener defs to expose their tab names statically — before EnterMsg runs with live data. The names and order must match the tabs EnterMsg produces. It lets the CLI validate and complete a `--tab` launch selection (see cmd/lazydbx) without opening the workspace.

type Tagger

type Tagger interface {
	RowTags(row Row) []string
}

Tagger is optionally implemented by defs whose rows carry tags (e.g. job custom tags). The browser offers an interactive tag filter for them. Returned tags should be stable, display-ready strings like "env=prod".

type WebLinker

type WebLinker interface {
	WebURL(host string, scope Scope, row Row) (url string, ok bool)
}

WebLinker is optionally implemented by defs whose rows map to a page in the Databricks workspace web UI. The browser binds `o` to open that page in the system browser. host is the workspace base URL (e.g. "https://xxx.cloud.databricks.com", no trailing slash); ok is false when the row has no stable web location (e.g. host unknown).

Jump to

Keyboard shortcuts

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