feature

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDependencies

func AddDependencies(projectRoot string, deps []Dependency) error

AddDependencies adds Go module dependencies to go.mod.

func AddInstalledFeature

func AddInstalledFeature(projectRoot, name, version string) error

AddInstalledFeature adds a feature to the installed list.

func FeaturesPath

func FeaturesPath(projectRoot string) string

FeaturesPath returns the path to the features tracking file.

func FileExists

func FileExists(path string) bool

FileExists checks if a file exists.

func IntegrateMainGo added in v0.3.1

func IntegrateMainGo(projectRoot string, integration MainIntegration) error

IntegrateMainGo safely integrates a feature into main.go

func IntegrateRouterGo added in v0.3.1

func IntegrateRouterGo(projectRoot string, integration RouterIntegration) error

IntegrateRouterGo safely integrates a feature into router.go It handles multiple features by properly merging imports and middleware calls

func MkdirAll

func MkdirAll(path string, perm os.FileMode) error

MkdirAll creates directories.

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile reads a file content.

func RemoveEnvironment

func RemoveEnvironment(projectRoot string, envVars []string) error

RemoveEnvironment removes environment variables from .env.example.

func RemoveInstalledFeature

func RemoveInstalledFeature(projectRoot, name string) error

RemoveInstalledFeature removes a feature from the installed list.

func RemoveMainGo added in v0.3.1

func RemoveMainGo(projectRoot string, integration MainIntegration) error

RemoveMainGo safely removes a feature's integration from main.go

func RemoveRouterGo added in v0.3.1

func RemoveRouterGo(projectRoot string, integration RouterIntegration) error

RemoveRouterGo safely removes a feature's integration from router.go It only removes the specific feature's import and middleware call, preserving other features

func RunGoFmt

func RunGoFmt(projectRoot string) error

RunGoFmt runs gofmt on all Go files in the project.

func RunGoModTidy

func RunGoModTidy(projectRoot string) error

RunGoModTidy runs go mod tidy in the project directory.

func SaveFeatures

func SaveFeatures(projectRoot string, f FeaturesFile) error

SaveFeatures saves the installed features to .forge/features.yaml.

func UpdateEnvironment

func UpdateEnvironment(projectRoot string, envVars []string) error

UpdateEnvironment appends environment variables to .env.example.

func WriteFile

func WriteFile(path string, content []byte) error

WriteFile writes content to a file.

Types

type Conflict

type Conflict struct {
	File        string
	Description string
}

Conflict describes a potential conflict during feature installation.

type ConflictInfo added in v0.3.1

type ConflictInfo struct {
	File        string
	Description string
	UserContent []byte
	PlanContent []byte
}

ConflictInfo represents a detected conflict

type Dependency

type Dependency struct {
	Module  string
	Version string
}

Dependency represents a Go module dependency.

type Detector

type Detector struct{}

Detector detects and loads information about a ForgeKit project.

func (Detector) Detect

func (Detector) Detect(root string) (ProjectContext, error)

Detect inspects the project root and returns its context. Strict mode: requires ForgeKit project structure (.forge or legacy features.yaml).

func (Detector) DetectLoose

func (Detector) DetectLoose(root string) (ProjectContext, error)

DetectLoose inspects the project root and returns its context. Loose mode: accepts ForgeKit projects, legacy projects, and external compatible Go projects.

type Feature

type Feature interface {
	Name() string
	Description() string
	Version() string

	Check(ctx context.Context, project ProjectContext) error
	Plan(ctx context.Context, project ProjectContext) (Plan, error)
	Apply(ctx context.Context, project ProjectContext, plan Plan) error
}

Feature represents an installable ForgeKit feature.

type FeatureDependencies

type FeatureDependencies interface {
	DependsOn() []string
}

FeatureDependencies is an optional interface for features that declare dependencies on other features.

type FeatureRemover

type FeatureRemover interface {
	Remove(ctx context.Context, project ProjectContext, plan Plan) error
}

FeatureRemover is an optional interface for features that support removal.

type FeaturesFile

type FeaturesFile struct {
	Features []InstalledFeature `yaml:"features"`
}

FeaturesFile represents the .forge/features.yaml file.

func LoadFeatures

func LoadFeatures(projectRoot string) (FeaturesFile, error)

LoadFeatures loads the installed features from .forge/features.yaml.

type FileAction

type FileAction struct {
	Source      string
	Destination string
	Action      FileActionType
}

FileAction describes a file operation performed by a feature.

type FileActionType

type FileActionType string

FileActionType represents the type of file operation.

const (
	FileActionCreate FileActionType = "create"
	FileActionModify FileActionType = "modify"
	FileActionDelete FileActionType = "delete"
)

type FileChange

type FileChange struct {
	Path       string
	Existed    bool
	OldContent []byte
	OldHash    string
}

FileChange represents a file modification for rollback tracking.

type InstalledFeature

type InstalledFeature struct {
	Name        string    `yaml:"name"`
	Version     string    `yaml:"version"`
	InstalledAt time.Time `yaml:"installed_at"`
}

InstalledFeature represents a feature installed in the project.

func IsInstalled

func IsInstalled(projectRoot, name string) (bool, *InstalledFeature, error)

IsInstalled checks if a feature is already installed.

type Installer

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

Installer applies feature plans with rollback capability.

func NewInstaller

func NewInstaller(projectRoot string, console *output.Console, dryRun bool) *Installer

NewInstaller creates an installer for a project.

func (*Installer) Apply

func (i *Installer) Apply(ctx context.Context, plan Plan) error

Apply executes a feature plan with rollback on failure.

func (*Installer) Changes

func (i *Installer) Changes() []FileChange

Changes returns the list of recorded changes (for inspection).

func (*Installer) Conflicts added in v0.3.1

func (i *Installer) Conflicts() []ConflictInfo

Conflicts returns the list of detected conflicts

func (*Installer) Rollback

func (i *Installer) Rollback() error

Rollback restores all modified files to their original state.

type MainIntegration added in v0.3.1

type MainIntegration struct {
	ModulePath   string
	ImportPath   string
	ImportCheck  string
	BlankImport  bool // If true, use blank import (_ "path") instead of regular import
	Replacements []MainReplacement
}

MainIntegration holds the configuration for integrating a feature into main.go

type MainReplacement added in v0.3.1

type MainReplacement struct {
	OldStr string
	NewStr string
	Check  string // Optional: only replace if Check is found
}

MainReplacement represents a string replacement in main.go

type Manifest

type Manifest struct {
	Name         string
	Version      string
	Description  string
	Dependencies []Dependency
	Files        []FileAction
	Environment  []string
}

Manifest describes the resources required by a feature.

type Plan

type Plan struct {
	Feature      string
	Version      string
	Files        []FileAction
	Dependencies []Dependency
	Environment  []string
	Conflicts    []Conflict
}

Plan describes the changes a feature intends to make.

type ProjectContext

type ProjectContext struct {
	Root      string
	Module    string
	GoVersion string
	HTTPPort  int
	Type      ProjectType
}

ProjectContext describes the ForgeKit project receiving a feature.

type ProjectType

type ProjectType int

ProjectType represents the type of project detected.

const (
	ProjectTypeUnknown ProjectType = iota
	ProjectTypeForgeKit
	ProjectTypeLegacyForgeKit
	ProjectTypeExternalCompatible
	ProjectTypeInvalidForgeKit
)

type Registry

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

Registry stores the available ForgeKit features.

func NewRegistry

func NewRegistry(features ...Feature) *Registry

NewRegistry creates a feature registry.

func (*Registry) Get

func (r *Registry) Get(name string) (Feature, bool)

Get returns a feature by name.

func (*Registry) HasCycles

func (r *Registry) HasCycles(names []string) bool

HasCycles checks if there are circular dependencies among the given feature names.

func (*Registry) List

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

List returns all registered features sorted by name.

func (*Registry) Register

func (r *Registry) Register(f Feature)

Register adds a feature to the registry.

func (*Registry) Require

func (r *Registry) Require(name string) (Feature, error)

Require returns a feature or an explicit error.

func (*Registry) ResolveDependencies

func (r *Registry) ResolveDependencies(names []string) ([]Feature, error)

ResolveDependencies returns features in topological order based on their DependsOn() declarations. Features without FeatureDependencies interface are treated as having no dependencies. Returns an error if a cycle is detected or a dependency is not registered.

type RollbackLimitation added in v0.3.1

type RollbackLimitation struct {
	CanRollback    []string
	CannotRollback []string
}

RollbackLimitation describes what rollback can and cannot do.

func GetRollbackLimitations added in v0.3.1

func GetRollbackLimitations() RollbackLimitation

GetRollbackLimitations returns the rollback capabilities and limitations.

type RollbackManager added in v0.3.1

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

RollbackManager manages project state snapshots for rollback operations.

func NewRollbackManager added in v0.3.1

func NewRollbackManager(projectRoot string) *RollbackManager

NewRollbackManager creates a new rollback manager for a project.

func (*RollbackManager) ClearSnapshots added in v0.3.1

func (rm *RollbackManager) ClearSnapshots()

ClearSnapshots removes all snapshots.

func (*RollbackManager) CreateSnapshot added in v0.3.1

func (rm *RollbackManager) CreateSnapshot(description string) (*Snapshot, error)

CreateSnapshot captures the current project state.

func (*RollbackManager) ListSnapshots added in v0.3.1

func (rm *RollbackManager) ListSnapshots() []*Snapshot

ListSnapshots returns all available snapshots.

func (*RollbackManager) RollbackLast added in v0.3.1

func (rm *RollbackManager) RollbackLast() error

RollbackLast restores to the most recent snapshot.

func (*RollbackManager) RollbackTo added in v0.3.1

func (rm *RollbackManager) RollbackTo(snap *Snapshot) error

RollbackTo restores the project state to a specific snapshot.

func (*RollbackManager) VerifyRollback added in v0.3.1

func (rm *RollbackManager) VerifyRollback(snap *Snapshot) error

VerifyRollback verifies that the project state matches the snapshot.

type RouterIntegration added in v0.3.1

type RouterIntegration struct {
	ModulePath      string
	ImportPath      string
	MiddlewareCall  string
	MiddlewareCheck string // String to check if already integrated
}

RouterIntegration holds the configuration for integrating a feature into router.go

type Snapshot added in v0.3.1

type Snapshot struct {
	ID          string
	Timestamp   time.Time
	GoMod       []byte
	GoSum       []byte
	ForgeFiles  map[string][]byte
	EnvExample  []byte
	Description string
}

Snapshot represents a complete project state at a point in time.

type TemplateRenderer

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

TemplateRenderer renders template files.

func NewTemplateRenderer

func NewTemplateRenderer(data map[string]string) *TemplateRenderer

NewTemplateRenderer creates a template renderer.

func (*TemplateRenderer) RenderFile

func (t *TemplateRenderer) RenderFile(sourcePath, destPath string) error

RenderFile reads a template file and replaces placeholders.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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