scaffold

package
v0.4.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package scaffold provides profile scaffolding functionality for the init command. It generates starter profiles and system configurations based on user-selected plugins.

Index

Constants

View Source
const DefaultOutputPath = "./reglet-profile.yaml"

DefaultOutputPath is the default output path for generated profiles.

Variables

View Source
var AvailablePlugins = []PluginInfo{
	{Name: "file", Description: "Validate file existence, permissions, and content"},
	{Name: "http", Description: "Check HTTP endpoints and responses"},
	{Name: "dns", Description: "Verify DNS records and resolution"},
	{Name: "tcp", Description: "Test TCP port connectivity"},
	{Name: "command", Description: "Execute shell commands and validate output"},
	{Name: "smtp", Description: "Validate SMTP server configuration"},
}

AvailablePlugins returns the list of plugins that can be selected during init.

Functions

func DefaultConfigPath

func DefaultConfigPath() string

DefaultConfigPath returns the default system config path. This is always ~/.reglet/config.yaml.

func EnsureConfigDir

func EnsureConfigDir(configPath string) error

EnsureConfigDir creates the config directory if it doesn't exist.

func ExpandConfigPath

func ExpandConfigPath(path string) (string, error)

ExpandConfigPath expands ~ in the config path to the user's home directory.

func ValidPluginNames

func ValidPluginNames() map[string]bool

ValidPluginNames returns a set of valid plugin names for validation.

func ValidateProfileName

func ValidateProfileName(name string) error

ValidateProfileName is a validation function for use with huh.Input. Returns an error if the name is invalid, nil otherwise.

Types

type CapabilityGrant

type CapabilityGrant struct {
	Kind    string // fs, network, exec, env
	Pattern string // e.g., "read:/etc/hostname", "outbound:80,443"
}

CapabilityGrant represents a single capability grant for config generation.

func GetCapabilitiesForPlugins

func GetCapabilitiesForPlugins(plugins []string) []CapabilityGrant

GetCapabilitiesForPlugins returns all capability grants needed for the given plugins. This aggregates capabilities from all plugin examples.

type ConfigGenerator

type ConfigGenerator struct{}

ConfigGenerator generates system configuration YAML content.

func NewConfigGenerator

func NewConfigGenerator() *ConfigGenerator

NewConfigGenerator creates a new ConfigGenerator.

func (*ConfigGenerator) Generate

func (cg *ConfigGenerator) Generate(plugins []string) ([]byte, error)

Generate creates config content for the given plugins.

type GeneratedProfile

type GeneratedProfile struct {
	// ProfilePath is the target output path for the profile
	ProfilePath string

	// ConfigPath is the target output path for the config (empty if not generated)
	ConfigPath string

	// ProfileContent is the raw YAML content of the generated profile
	ProfileContent []byte

	// ConfigContent is the raw YAML content of the config (nil if not generated)
	ConfigContent []byte
}

GeneratedProfile holds the result of profile generation.

type InitOptions

type InitOptions struct {
	// ProfileName is the name for the generated profile (required)
	ProfileName string

	// OutputPath is where to write the generated profile (default: ./reglet-profile.yaml)
	OutputPath string

	// Plugins is the list of selected plugins to include (required, 1-6 items)
	Plugins []string

	// WithConfig indicates whether to generate ~/.reglet/config.yaml
	WithConfig bool

	// Force allows overwriting existing files without prompting
	Force bool
}

InitOptions holds the configuration collected from the wizard or CLI flags. This value object encapsulates all user inputs needed for profile generation.

func (*InitOptions) Validate

func (o *InitOptions) Validate() error

Validate checks that all required fields are present and valid. Returns an error describing the first validation failure, or nil if valid.

type PluginExample

type PluginExample struct {
	// PluginName is the plugin identifier (file, http, etc.)
	PluginName string

	// ControlID is the unique identifier for the example control
	ControlID string

	// ControlName is the human-readable name for the control
	ControlName string

	// Description explains what the example demonstrates
	Description string

	// ConfigYAML is the plugin-specific configuration as a YAML fragment
	// This is embedded directly in the generated profile
	ConfigYAML string

	// ExpectExpressions are the example expect expressions
	ExpectExpressions []string

	// Capabilities lists the required capability grants for this example
	Capabilities []CapabilityGrant
}

PluginExample represents a template for a single plugin's example control. Each plugin type has one example demonstrating its basic usage.

func GetPluginExample

func GetPluginExample(pluginName string) *PluginExample

GetPluginExample returns the example configuration for a specific plugin. Returns nil if the plugin is not found.

func GetPluginExamples

func GetPluginExamples(plugins []string) []PluginExample

GetPluginExamples returns examples for the specified plugins. Unknown plugins are silently skipped.

type PluginInfo

type PluginInfo struct {
	Name        string // Plugin identifier
	Description string // User-facing description for selection UI
}

PluginInfo provides metadata about available plugins.

type ProfileGenerator

type ProfileGenerator struct{}

ProfileGenerator generates profile YAML content from InitOptions.

func NewProfileGenerator

func NewProfileGenerator() *ProfileGenerator

NewProfileGenerator creates a new ProfileGenerator.

func (*ProfileGenerator) Generate

func (g *ProfileGenerator) Generate(opts *InitOptions) (*GeneratedProfile, error)

Generate creates profile content from the provided options. Returns an error if options are invalid or template execution fails.

Jump to

Keyboard shortcuts

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