buildr/modules/api.go

80 lines
1.5 KiB
Go
Raw Normal View History

2023-03-15 17:56:38 +00:00
package modules
import (
"context"
"io"
"log/slog"
2023-03-15 17:56:38 +00:00
"code.icb4dc0.de/buildr/buildr/modules/state"
"github.com/hashicorp/hcl/v2"
2023-03-15 17:56:38 +00:00
)
type ExecutionContext interface {
context.Context
2023-05-24 20:10:01 +00:00
Name() string
WorkingDir() string
OutDir() string
BinariesDir() string
StdOut() io.Writer
StdErr() io.Writer
2023-03-15 17:56:38 +00:00
Logger() *slog.Logger
GetState(ctx context.Context, key string) ([]byte, state.Metadata, error)
SetState(ctx context.Context, key string, value []byte) error
}
type StateEncoder[T any] interface {
Get(ctx context.Context, key string) (val T, ok bool, meta state.Metadata, err error)
Set(ctx context.Context, key string, val T) error
2023-03-15 17:56:38 +00:00
}
type ModuleWithMeta interface {
Module
Unwrap() Module
2023-05-24 20:10:01 +00:00
SetModule(m Module)
2023-03-15 17:56:38 +00:00
ID() string
Name() string
SetName(name string)
ShouldSkip() bool
2023-03-15 17:56:38 +00:00
Dependencies() []string
InputMappings() map[string]string
OutDir() string
ContainerSpec() *ContainerSpec
UnmarshalHCL(body hcl.Body, ctx *hcl.EvalContext) hcl.Diagnostics
2023-03-15 17:56:38 +00:00
}
2023-05-24 20:10:01 +00:00
type Initializer interface {
Init(hclCtx *hcl.EvalContext) (Module, error)
}
type Helper interface {
Help(ctx context.Context) (help Help, err error)
}
type Module interface {
Execute(ctx ExecutionContext) error
Category() Category
Type() string
2023-03-15 17:56:38 +00:00
}
type BinaryNamer interface {
BinaryName(ctx context.Context) (binaryName string, err error)
}
type ToolModule interface {
Module
BinaryNamer
}
type Factory interface {
Create() ModuleWithMeta
2023-04-11 20:30:48 +00:00
}
var _ Factory = (*ModuleFactoryFunc)(nil)
2023-04-11 20:30:48 +00:00
type ModuleFactoryFunc func() ModuleWithMeta
2023-04-11 20:30:48 +00:00
func (f ModuleFactoryFunc) Create() ModuleWithMeta {
2023-04-11 20:30:48 +00:00
return f()
2023-03-15 17:56:38 +00:00
}