hints

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package hints provides formatting for hints in different output formats.

Package hints provides actionable user guidance for CLI operations.

Package hints provides context-aware hint providers for Starmap CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Display

func Display(w io.Writer, format format.Format, hints []*Hint) error

Display is a convenience function to format and display hints.

func DisplayHint

func DisplayHint(w io.Writer, format format.Format, hint *Hint) error

DisplayHint is a convenience function to format and display a single hint.

func RegisterStarmapProviders

func RegisterStarmapProviders(registry *Registry)

RegisterStarmapProviders registers all standard Starmap hint providers.

Types

type Context

type Context struct {
	Command     string            // Current command being executed
	Subcommand  string            // Subcommand if applicable
	Succeeded   bool              // Whether the operation succeeded
	ErrorType   string            // Type of error if failed
	Args        []string          // Command arguments
	Flags       map[string]string // Command flags
	UserState   UserState         // Current user state
	Environment Environment       // Runtime environment
}

Context provides information for generating contextual hints.

type Environment

type Environment struct {
	IsTerminal bool   // Whether running in a terminal
	IsCI       bool   // Whether running in CI/CD
	Shell      string // Shell type (bash, zsh, etc.)
	OS         string // Operating system
	WorkingDir string // Current working directory
	IsGitRepo  bool   // Whether in a git repository
}

Environment represents the runtime environment.

type Formatter

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

Formatter formats hints for different output types.

func NewFormatter

func NewFormatter(w io.Writer, format format.Format) *Formatter

NewFormatter creates a new hint formatter.

func (*Formatter) FormatHint

func (f *Formatter) FormatHint(hint *Hint) error

FormatHint formats and writes a single hint.

func (*Formatter) FormatHints

func (f *Formatter) FormatHints(hints []*Hint) error

FormatHints formats and writes a slice of hints.

func (*Formatter) WithConfig

func (f *Formatter) WithConfig(config FormatterConfig) *Formatter

WithConfig sets the formatter configuration.

type FormatterConfig

type FormatterConfig struct {
	ShowIcons  bool // Whether to show emoji icons
	MaxWidth   int  // Maximum width for text wrapping
	IndentSize int  // Indentation size for structured output
}

FormatterConfig configures hint formatting behavior.

type Hint

type Hint struct {
	Message string   // Human-readable guidance message
	Command string   // Optional specific command to run
	URL     string   // Optional documentation link
	Tags    []string // For context-aware filtering
}

Hint represents actionable user guidance.

func New

func New(message string) *Hint

New creates a new hint with the given message.

func NewCommand

func NewCommand(message, command string) *Hint

NewCommand creates a new hint with a specific command.

func NewURL

func NewURL(message, url string) *Hint

NewURL creates a new hint with a documentation URL.

func (*Hint) HasTag

func (h *Hint) HasTag(tag string) bool

HasTag checks if the hint has a specific tag.

func (*Hint) String

func (h *Hint) String() string

String returns a string representation of the hint.

func (*Hint) WithCommand

func (h *Hint) WithCommand(command string) *Hint

WithCommand adds a command to the hint.

func (*Hint) WithTags

func (h *Hint) WithTags(tags ...string) *Hint

WithTags adds tags to the hint for context-aware filtering.

func (*Hint) WithURL

func (h *Hint) WithURL(url string) *Hint

WithURL adds a URL to the hint.

type Provider

type Provider interface {
	GetHints(ctx Context) []*Hint
	Name() string
}

Provider generates contextual hints based on the current context.

type ProviderFunc

type ProviderFunc func(Context) []*Hint

ProviderFunc is an adapter to allow functions to be used as Providers.

func (ProviderFunc) GetHints

func (f ProviderFunc) GetHints(ctx Context) []*Hint

GetHints calls the function.

func (ProviderFunc) Name

func (f ProviderFunc) Name() string

Name returns the function name (generic).

type Registry

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

Registry manages hint providers and generates contextual hints.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new hint registry.

func (*Registry) GetHints

func (r *Registry) GetHints(ctx Context) []*Hint

GetHints generates hints for the given context.

func (*Registry) Register

func (r *Registry) Register(provider Provider)

Register adds a hint provider to the registry.

func (*Registry) RegisterFunc

func (r *Registry) RegisterFunc(name string, fn func(Context) []*Hint)

RegisterFunc registers a function as a hint provider.

func (*Registry) WithConfig

func (r *Registry) WithConfig(config RegistryConfig) *Registry

WithConfig sets the registry configuration.

type RegistryConfig

type RegistryConfig struct {
	MaxHints    int      // Maximum number of hints to return
	FilterTags  []string // Only include hints with these tags
	ExcludeTags []string // Exclude hints with these tags
	Enabled     bool     // Whether hints are enabled
}

RegistryConfig configures hint generation behavior.

type UserState

type UserState struct {
	AuthProviders    []string // Configured authentication providers
	HasConfig        bool     // Whether user has configuration file
	IsFirstRun       bool     // Whether this is the first time running
	LastCommand      string   // Last successful command
	ConfiguredOutput string   // User's preferred output format
}

UserState represents the current state of user configuration.

Jump to

Keyboard shortcuts

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