notify

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: 12 Imported by: 0

Documentation

Overview

Package notify provides context detection for smart hint generation.

Package notify provides a unified API for alerts and hints in the CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alert

func Alert(alert *alerts.Alert) error

Alert sends an alert using the default notifier.

func Error

func Error(message string, ctx hints.Context) error

Error sends an error alert using the default notifier.

func Hints

func Hints(ctx hints.Context) error

Hints displays hints using the default notifier.

func Info

func Info(message string, ctx hints.Context) error

Info sends an info alert using the default notifier.

func SetDefault

func SetDefault(notifier *Notifier)

SetDefault sets the default global notifier.

func Success

func Success(message string, ctx hints.Context) error

Success sends a success alert using the default notifier.

func Warning

func Warning(message string, ctx hints.Context) error

Warning sends a warning alert using the default notifier.

Types

type CommonContexts

type CommonContexts struct{}

CommonContexts provides pre-built contexts for common scenarios.

var Contexts CommonContexts

Contexts is the global contexts instance for convenience.

func (CommonContexts) AuthStatus

func (CommonContexts) AuthStatus(succeeded bool, providersConfigured int) hints.Context

AuthStatus creates a context for auth status commands.

func (CommonContexts) AuthTest added in v0.0.24

func (CommonContexts) AuthTest(succeeded bool, errorType string) hints.Context

AuthTest creates a context for auth testing commands.

func (CommonContexts) Command

func (CommonContexts) Command(command, subcommand string, succeeded bool, errorType string) hints.Context

Command creates a context for generic command execution.

func (CommonContexts) Validation

func (CommonContexts) Validation(subcommand string, succeeded bool, errorType string) hints.Context

Validation creates a context for validation commands.

type Config

type Config struct {
	OutputFormat string    // "table", "json", "yaml"
	ShowHints    bool      // Whether to show hints
	ShowAlerts   bool      // Whether to show alerts
	MaxHints     int       // Maximum number of hints to show
	AlertWriter  io.Writer // Where to write alerts (default: stderr)
	HintWriter   io.Writer // Where to write hints (default: stdout)
	UseColor     bool      // Whether to use colored output
}

Config controls notification behavior.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a sensible default configuration.

type ContextBuilder

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

ContextBuilder helps build hint contexts from command execution.

func NewContextBuilder

func NewContextBuilder() *ContextBuilder

NewContextBuilder creates a new context builder.

func (*ContextBuilder) Build

func (cb *ContextBuilder) Build() hints.Context

Build returns the constructed context.

func (*ContextBuilder) FromCommand

func (cb *ContextBuilder) FromCommand(cmd *cobra.Command, args []string) *ContextBuilder

FromCommand configures the context from a Cobra command.

func (*ContextBuilder) WithError

func (cb *ContextBuilder) WithError(errorType string) *ContextBuilder

WithError sets the error type for failed operations.

func (*ContextBuilder) WithSuccess

func (cb *ContextBuilder) WithSuccess(succeeded bool) *ContextBuilder

WithSuccess sets the operation success status.

func (*ContextBuilder) WithUserState

func (cb *ContextBuilder) WithUserState(userState hints.UserState) *ContextBuilder

WithUserState updates the user state information.

type Notifier

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

Notifier is the main public API for sending alerts and displaying hints.

func GetDefault

func GetDefault() *Notifier

GetDefault returns the default global notifier, creating one if needed.

func New

func New(config Config) *Notifier

New creates a new Notifier with the given configuration.

func NewFromCommand

func NewFromCommand(cmd *cobra.Command) (*Notifier, error)

NewFromCommand creates a Notifier configured from a Cobra command.

func (*Notifier) AddHintFunc

func (n *Notifier) AddHintFunc(name string, fn func(hints.Context) []*hints.Hint)

AddHintFunc registers a function as a hint provider.

func (*Notifier) AddHintProvider

func (n *Notifier) AddHintProvider(provider hints.Provider)

AddHintProvider registers a custom hint provider.

func (*Notifier) Alert

func (n *Notifier) Alert(alert *alerts.Alert) error

Alert sends an alert notification.

func (*Notifier) AlertWithHints

func (n *Notifier) AlertWithHints(alert *alerts.Alert, ctx hints.Context) error

AlertWithHints sends an alert and displays contextual hints.

func (*Notifier) Error

func (n *Notifier) Error(message string, ctx hints.Context) error

Error sends an error alert with optional hints.

func (*Notifier) Hints

func (n *Notifier) Hints(ctx hints.Context) error

Hints displays contextual hints without an alert.

func (*Notifier) Info

func (n *Notifier) Info(message string, ctx hints.Context) error

Info sends an info alert with optional hints.

func (*Notifier) Success

func (n *Notifier) Success(message string, ctx hints.Context) error

Success sends a success alert with optional hints.

func (*Notifier) Warning

func (n *Notifier) Warning(message string, ctx hints.Context) error

Warning sends a warning alert with optional hints.

func (*Notifier) WithConfig

func (n *Notifier) WithConfig(config Config) *Notifier

WithConfig creates a new Notifier with updated configuration.

Jump to

Keyboard shortcuts

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