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 ¶
- type Action
- type AltWebLinker
- type CellClass
- type ColSpec
- type Column
- type Command
- type Def
- type Opener
- type Registry
- func (r *Registry) Canonical() []string
- func (r *Registry) Complete(prefix string) []string
- func (r *Registry) Get(nameOrAlias string) (Def, bool)
- func (r *Registry) MustRegister(d Def)
- func (r *Registry) Names() []string
- func (r *Registry) Parse(input string) (Command, error)
- func (r *Registry) ParseArgs(fields []string) (Command, error)
- func (r *Registry) Summaries() []string
- type Row
- type RowNamer
- type Scope
- type Styler
- type Tabber
- type Tagger
- type WebLinker
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).
type ColSpec ¶
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.
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 ¶
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 (*Registry) Canonical ¶
Canonical returns only the canonical resource names, sorted — shown when the command bar opens empty, so every resource is discoverable.
func (*Registry) Complete ¶
Complete returns registered names with the given prefix, for autocomplete.
func (*Registry) MustRegister ¶
MustRegister adds a def, panicking on name/alias collisions — collisions are programmer error and should fail at startup, loudly.
func (*Registry) Names ¶
Names returns all canonical names plus aliases, sorted — the completion source for the command bar.
func (*Registry) Parse ¶
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 ¶
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.
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 (Row) MatchesFilter ¶
MatchesFilter reports whether any cell contains the filter text (case-insensitive substring). An empty filter matches everything.
type RowNamer ¶
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 ¶
Scope parameterizes a view, e.g. {"catalog": "main", "schema": "silver"} for a tables view or {"job_id": "123"} for a runs view.
type Styler ¶
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 ¶
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 ¶
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).