capability

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package capability derives a feature set from the active context's configuration: which transports are usable (chain RPC, Console API) and therefore which command groups can work. The CLI uses it to gate the command surface so users are never offered commands their configuration cannot execute — e.g. a context with only a Console API key and no RPC endpoint cannot run chain queries.

Two presentation modes are supported while UX feedback is collected (config: defaults.command-gating):

  • "dim" (default): unavailable commands stay listed, marked "[unavailable: ...]" in help, and fail fast with an explanation.
  • "hide": unavailable commands are removed from help listings entirely (still fail fast with the explanation if invoked directly).
  • "off": no gating; commands fail wherever the missing transport is first touched (the pre-gating behavior).

Index

Constants

View Source
const AnnotationKey = "akt.requires"

AnnotationKey is the cobra annotation carrying a command's requirement. The value is a requirement expression: capabilities separated by "|" are alternatives (any one suffices), e.g. "chain-tx|console" for workflow commands that run on either rail.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capability

type Capability string

Capability names a single thing a context configuration can do.

const (
	// ChainQuery requires a network RPC endpoint.
	ChainQuery Capability = "chain-query"
	// ChainTx requires a network RPC endpoint (transactions additionally
	// need a funded key at execution time; key presence is deliberately
	// not probed here because opening OS keyrings can prompt).
	ChainTx Capability = "chain-tx"
	// Console requires a resolvable Console API key.
	Console Capability = "console"
	// Provider requires chain access (gateway discovery + wallet auth).
	Provider Capability = "provider"
)

type Mode

type Mode string

Mode is the gating presentation mode from config.

const (
	ModeDim  Mode = "dim"
	ModeHide Mode = "hide"
	ModeOff  Mode = "off"
)

func ParseMode

func ParseMode(s string) Mode

ParseMode normalizes a configured gating mode; unknown values fall back to the default (dim) so a config typo never disables the safety net.

type Set

type Set struct {
	ChainQuery bool
	ChainTx    bool
	Console    bool
	Provider   bool
}

Set is the feature set resolved from a context.

func Resolve

func Resolve(rc *aktctx.Context) Set

Resolve derives the feature set from a resolved context. A nil context (no active context) yields the empty set.

func (Set) Explain

func (s Set) Explain(requirement string) string

Explain describes an unsatisfied requirement and how to fix it. The returned string is suitable both for help-line dimming and for the error returned when the command is invoked anyway.

func (Set) Has

func (s Set) Has(c Capability) bool

Has reports whether the set satisfies a single capability.

func (Set) Satisfies

func (s Set) Satisfies(requirement string) bool

Satisfies evaluates a requirement expression against the set.

Jump to

Keyboard shortcuts

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