features

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package features defines the core feature interface and common functionality

Package features provides the core feature interface and registry

Index

Constants

This section is empty.

Variables

View Source
var (
	RegisterUserFeature     func(*Registry, *osdetect.Info)
	RegisterSSHFeature      func(*Registry, *osdetect.Info)
	RegisterSudoFeature     func(*Registry, *osdetect.Info)
	RegisterSecurityFeature func(*Registry, *osdetect.Info)
)

Feature registration functions

Functions

func RegisterFeatures

func RegisterFeatures(registry *Registry, osInfo *osdetect.Info)

RegisterFeatures registers all features with the registry

Types

type ExecutionContext

type ExecutionContext struct {
	// Options contains the parsed command-line options
	Options map[string]any

	// Logger is the logger instance
	Logger *logger.Logger

	// DryRun indicates if the feature should only simulate execution
	DryRun bool

	// Interactive indicates if the feature should prompt for user input
	Interactive bool

	// Verbose indicates if the feature should output verbose information
	Verbose bool
}

ExecutionContext provides context for feature execution

type Feature

type Feature interface {
	// Name returns the feature name
	Name() string

	// Description returns the feature description
	Description() string

	// Flags returns the command-line flags for the feature
	Flags() []Flag

	// ShouldActivate determines if the feature should be activated based on options
	ShouldActivate(options map[string]any) bool

	// ValidateOptions validates the feature options
	ValidateOptions(options map[string]any) error

	// Execute executes the feature functionality
	Execute(ctx *ExecutionContext) error

	// Priority returns the feature execution priority (lower numbers run first)
	Priority() int

	// DetectCurrentState detects and returns the current state of the feature
	// The returned map contains state information that can be used for display and decision making
	DetectCurrentState(ctx *ExecutionContext) (map[string]any, error)

	// DisplayCurrentState displays the current state of the feature to the user
	// This is used in interactive mode to show the user the current state before prompting
	DisplayCurrentState(ctx *ExecutionContext, state map[string]any)

	// ShouldPromptUser determines if the user should be prompted for input based on the current state
	// This allows features to skip prompting if the current state already matches the desired state
	ShouldPromptUser(ctx *ExecutionContext, state map[string]any) bool
}

Feature defines the interface that all features must implement

func SortFeaturesByPriority

func SortFeaturesByPriority(features []Feature) []Feature

SortFeaturesByPriority sorts features by priority (lower numbers first)

type Flag

type Flag struct {
	// Name is the long name of the flag (e.g., "user")
	Name string

	// Shorthand is the short name of the flag (e.g., "u")
	Shorthand string

	// Usage is the help text for the flag
	Usage string

	// Default is the default value for the flag
	Default any

	// Required indicates if the flag is required
	Required bool
}

Flag represents a command-line flag for a feature

type Registry

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

Registry manages the registration and retrieval of features

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new feature registry

func (*Registry) GetActiveFeatures

func (r *Registry) GetActiveFeatures(options map[string]any) []Feature

GetActiveFeatures returns features that should be activated based on options

func (*Registry) GetFeatures

func (r *Registry) GetFeatures() []Feature

GetFeatures returns all registered features

func (*Registry) Register

func (r *Registry) Register(feature Feature)

Register registers a feature with the registry

Directories

Path Synopsis
Package security implements the SSH security configuration feature
Package security implements the SSH security configuration feature
Package ssh implements the SSH key management feature
Package ssh implements the SSH key management feature
Package sudo implements the sudo configuration feature
Package sudo implements the sudo configuration feature
Package user implements the user management feature
Package user implements the user management feature

Jump to

Keyboard shortcuts

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