props

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 22 Imported by: 0

README

Props

The core dependency injection container for GTB applications.

Props holds global state including:

  • Tool metadata
  • Logger instance
  • Configuration container
  • Filesystem abstraction (Afero)
  • Version information

For detailed documentation on design rationale and usage patterns, see the Props Component Documentation.

Documentation

Overview

Package props defines the Props dependency container, the central type-safe dependency injection mechanism used throughout GTB.

Props is a concrete struct that aggregates tool metadata, logger, configuration, filesystem (afero.Fs), embedded assets, version info, and error handler into a single value threaded through commands and services. It replaces context.Context-based DI with compile-time type safety.

The package also provides the feature flag system via SetFeatures, Enable, and Disable functional options, controlling which built-in commands (update, init, docs, mcp) are registered at startup. Tool release source metadata for GitHub and GitLab backends is managed through ReleaseSource.

Index

Constants

View Source
const (
	UpdateCmd = FeatureCmd("update")
	InitCmd   = FeatureCmd("init")
	McpCmd    = FeatureCmd("mcp")
	DocsCmd   = FeatureCmd("docs")
	AiCmd     = FeatureCmd("ai")
	DoctorCmd = FeatureCmd("doctor")
)

Variables

DefaultFeatures is the list of features enabled by default.

Functions

This section is empty.

Types

type AssetMap

type AssetMap map[string]fs.FS

AssetMap is a custom type for a map of filesystems.

type AssetProvider

type AssetProvider interface {
	GetAssets() Assets
}

AssetProvider provides access to embedded assets.

type Assets

type Assets interface {
	fs.FS
	fs.ReadDirFS
	fs.GlobFS
	fs.StatFS

	Slice() []fs.FS
	Names() []string
	Get(name string) fs.FS
	Register(name string, fs fs.FS)
	For(names ...string) Assets
	Merge(others ...Assets) Assets
	Exists(name string) (fs.FS, error)
	Mount(f fs.FS, prefix string)
}

Assets is an interface that wraps a map of fs.FS pointers and implements the standard fs interfaces.

func NewAssets

func NewAssets(assets ...AssetMap) Assets

NewAssets creates a new Assets wrapper with the given AssetMap pointers.

type ConfigProvider

type ConfigProvider interface {
	GetConfig() config.Containable
}

ConfigProvider provides access to the application configuration.

type CoreProvider

type CoreProvider interface {
	LoggerProvider
	ConfigProvider
	FileSystemProvider
}

CoreProvider provides the three most commonly needed capabilities.

type ErrorHandlerProvider

type ErrorHandlerProvider interface {
	GetErrorHandler() errorhandling.ErrorHandler
}

ErrorHandlerProvider provides access to the error handler.

type Feature

type Feature struct {
	Cmd     FeatureCmd `json:"cmd" yaml:"cmd"`
	Enabled bool       `json:"enabled" yaml:"enabled"`
}

Feature represents the state of a feature (Enabled/Disabled).

func SetFeatures

func SetFeatures(mutators ...FeatureState) []Feature

SetFeatures applies a series of mutators to the standard default set.

type FeatureCmd

type FeatureCmd string

type FeatureState

type FeatureState func([]Feature) []Feature

FeatureState is a functional option that mutates the list of features.

func Disable

func Disable(cmd FeatureCmd) FeatureState

Disable returns a FeatureState that disables the given command.

func Enable

func Enable(cmd FeatureCmd) FeatureState

Enable returns a FeatureState that enables the given command.

type FileSystemProvider

type FileSystemProvider interface {
	GetFS() afero.Fs
}

FileSystemProvider provides access to the application filesystem.

type LoggerProvider

type LoggerProvider interface {
	GetLogger() logger.Logger
}

LoggerProvider provides access to the application logger.

type LoggingConfigProvider

type LoggingConfigProvider interface {
	LoggerProvider
	ConfigProvider
}

LoggingConfigProvider is the most common combination — logging and configuration.

type Props

type Props struct {
	Tool         Tool
	Logger       logger.Logger
	Config       config.Containable
	Assets       Assets
	FS           afero.Fs
	Version      version.Version
	ErrorHandler errorhandling.ErrorHandler
}

Props is the primary dependency injection container for GTB applications. When writing functions that accept Props, consider whether a narrow interface (LoggerProvider, ConfigProvider, etc.) would suffice.

func (*Props) GetAssets

func (p *Props) GetAssets() Assets

GetAssets returns the embedded assets.

func (*Props) GetConfig

func (p *Props) GetConfig() config.Containable

GetConfig returns the application configuration.

func (*Props) GetErrorHandler

func (p *Props) GetErrorHandler() errorhandling.ErrorHandler

GetErrorHandler returns the error handler.

func (*Props) GetFS

func (p *Props) GetFS() afero.Fs

GetFS returns the application filesystem.

func (*Props) GetLogger

func (p *Props) GetLogger() logger.Logger

GetLogger returns the application logger.

func (*Props) GetTool

func (p *Props) GetTool() Tool

GetTool returns the tool metadata.

func (*Props) GetVersion

func (p *Props) GetVersion() version.Version

GetVersion returns the version information.

type ReleaseSource

type ReleaseSource struct {
	Type    string `json:"type" yaml:"type"`
	Host    string `json:"host" yaml:"host"`
	Owner   string `json:"owner" yaml:"owner"`
	Repo    string `json:"repo" yaml:"repo"`
	Private bool   `json:"private" yaml:"private"`
}

type Tool

type Tool struct {
	Name        string                   `json:"name" yaml:"name"`
	Summary     string                   `json:"summary" yaml:"summary"`
	Description string                   `json:"description" yaml:"description"`
	Features    []Feature                `json:"features" yaml:"features"`
	Help        errorhandling.HelpConfig `json:"-" yaml:"-"`

	// ReleaseSource is the source of truth for the tool's releases (GitHub or GitLab)
	ReleaseSource ReleaseSource `json:"release_source" yaml:"release_source"`
}

func (Tool) GetReleaseSource

func (t Tool) GetReleaseSource() (sourceType, owner, repo string)

GetReleaseSource returns the release source type, owner, and repo.

func (Tool) IsDisabled

func (t Tool) IsDisabled(cmd FeatureCmd) bool

IsDisabled checks if a feature is disabled.

func (Tool) IsEnabled

func (t Tool) IsEnabled(cmd FeatureCmd) bool

IsEnabled checks if a feature is enabled. It checks the Features slice first, falling back to built-in defaults.

type ToolMetadataProvider

type ToolMetadataProvider interface {
	GetTool() Tool
}

ToolMetadataProvider provides access to tool configuration and metadata.

type VersionProvider

type VersionProvider interface {
	GetVersion() version.Version
}

VersionProvider provides access to version information.

Jump to

Keyboard shortcuts

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