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
- Variables
- type AssetMap
- type AssetProvider
- type Assets
- type ConfigProvider
- type CoreProvider
- type ErrorHandlerProvider
- type Feature
- type FeatureCmd
- type FeatureState
- type FileSystemProvider
- type LoggerProvider
- type LoggingConfigProvider
- type Props
- type ReleaseSource
- type Tool
- type ToolMetadataProvider
- type VersionProvider
Constants ¶
const ( UpdateCmd = FeatureCmd("update") InitCmd = FeatureCmd("init") McpCmd = FeatureCmd("mcp") DocsCmd = FeatureCmd("docs") AiCmd = FeatureCmd("ai") )
Variables ¶
var DefaultFeatures = []FeatureState{ Enable(UpdateCmd), Enable(InitCmd), Enable(McpCmd), Enable(DocsCmd), }
DefaultFeatures is the list of features enabled by default.
Functions ¶
This section is empty.
Types ¶
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.
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 ¶
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 ¶
FileSystemProvider provides access to the application filesystem.
type LoggerProvider ¶
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) 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) GetVersion ¶
GetVersion returns the version information.
type ReleaseSource ¶
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 ¶
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 ¶
VersionProvider provides access to version information.