commands

package
v0.1.0-dev.20260813053751 Latest Latest
Warning

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

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

Documentation

Overview

Package commands provides command tree navigation and execution for the star runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandFlag

type CommandFlag struct {
	Name    string `starlark:"name"`
	Help    string `starlark:"help"`
	Default string `starlark:"default"`
}

CommandFlag represents a command flag.

type CommandInfo

type CommandInfo struct {
	Name  string        `starlark:"name"`
	Help  string        `starlark:"help"`
	Flags []CommandFlag `starlark:"flags"`
}

CommandInfo describes a registered extension command.

type CommandRef

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

CommandRef wraps a command for use in Starlark. It implements starlark.Value and starlark.HasAttrs, exposing name, help, flags, and a callable run method.

func NewCommandRef

func NewCommandRef(name string, tree CommandTree) *CommandRef

NewCommandRef creates a new CommandRef.

func (*CommandRef) Attr

func (r *CommandRef) Attr(name string) (starlark.Value, error)

Attr implements starlark.HasAttrs.

func (*CommandRef) AttrNames

func (r *CommandRef) AttrNames() []string

AttrNames implements starlark.HasAttrs.

func (*CommandRef) Freeze

func (r *CommandRef) Freeze()

Freeze implements starlark.Value.

func (*CommandRef) Hash

func (r *CommandRef) Hash() (uint32, error)

Hash implements starlark.Value.

func (*CommandRef) String

func (r *CommandRef) String() string

String implements starlark.Value.

func (*CommandRef) Truth

func (r *CommandRef) Truth() starlark.Bool

Truth implements starlark.Value.

func (*CommandRef) Type

func (r *CommandRef) Type() string

Type implements starlark.Value.

type CommandTree

type CommandTree interface {
	// CommandNames returns all registered command names (space-separated).
	CommandNames() []string

	// RunCommand executes a command by space-separated name with the given flags
	// and optional positional arguments.
	RunCommand(name string, flags map[string]string, positional ...string) error

	// CommandHelp returns the help text for a command.
	CommandHelp(name string) string

	// CommandFlags returns the flags for a command as (name, help, default) tuples.
	CommandFlags(name string) []CommandFlag
}

CommandTree provides access to the command hierarchy. The Runtime implements this interface and injects it via context Data["command_tree"].

type Provider

type Provider struct {
	op.ProviderBase
}

Provider provides command tree navigation and execution operations.

+devlore:access=immediate

func NewProvider

func NewProvider(ctx *op.RuntimeEnvironment) *Provider

NewProvider creates a commands provider bound to the given context. Declares interest in the "command_tree" variable so the resolver populates it from the [application.Application]'s source maps at construction time. The "current_command" handle is read per-dispatch from [op.RuntimeEnvironment.Application.Overrides] directly — it mutates as cobra dispatches each subcommand, which doesn't fit the construction-time resolution model.

func (*Provider) Children

func (p *Provider) Children(parent string) ([]*CommandRef, error)

Children returns all child commands of the given parent path.

+devlore:defaults parent=""

Parameters:

  • parent: parent path to search (default: current command's parent)

Returns:

  • []*CommandRef: child commands
  • error: never

func (*Provider) Current

func (p *Provider) Current() (string, error)

Current returns the name of the currently executing command.

Returns:

  • string: the dot-separated command name
  • error: never

func (*Provider) Get

func (p *Provider) Get(name string) (*CommandRef, error)

Get returns a specific command by name, or nil if not found.

Parameters:

  • name: dot-separated command name

Returns:

  • *CommandRef: the command, or nil
  • error: never

func (*Provider) Parent

func (p *Provider) Parent() (string, error)

Parent returns the parent path of the current command.

Returns:

  • string: the parent path (e.g., "lint" for "lint.all")
  • error: never

func (*Provider) Query

func (p *Provider) Query(pattern string) ([]*CommandRef, error)

Query returns commands matching a pattern with * wildcards.

Parameters:

  • pattern: glob pattern (e.g., "lint.*", "*.go", "*")

Returns:

  • []*CommandRef: matching commands
  • error: never

func (*Provider) Run

func (p *Provider) Run(name string, flags map[string]string) (RunResult, error)

Run executes a command by name with the given arguments.

Parameters:

  • name: dot-separated command name
  • flags: keyword arguments passed to the command

Returns:

  • RunResult: pass/fail and error message
  • error: if command not found

func (*Provider) Siblings

func (p *Provider) Siblings() ([]*CommandRef, error)

Siblings returns all sibling commands (same parent, excluding self).

Returns:

  • []*CommandRef: sibling commands
  • error: never

type RunResult

type RunResult struct {
	Passed bool   `starlark:"passed"`
	Error  string `starlark:"error"`
}

RunResult holds the outcome of a command execution.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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