feat: engine -> process, engine is now a factory for a proces
This commit is contained in:
41
internal/cli/process.go
Normal file
41
internal/cli/process.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.maximhutz.com/max/lambda/pkg/engine"
|
||||
)
|
||||
|
||||
type Process interface {
|
||||
engine.Process[Repr]
|
||||
|
||||
InType() string
|
||||
}
|
||||
|
||||
type convertedProcess[T any] struct {
|
||||
process engine.Process[T]
|
||||
inType string
|
||||
}
|
||||
|
||||
func (e convertedProcess[T]) InType() string { return e.inType }
|
||||
|
||||
func (b convertedProcess[T]) Get() (Repr, error) {
|
||||
s, err := b.process.Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewRepr(b.inType, s), nil
|
||||
}
|
||||
|
||||
func (b convertedProcess[T]) Set(r Repr) error {
|
||||
if t, ok := r.Data().(T); ok {
|
||||
return b.process.Set(t)
|
||||
}
|
||||
|
||||
return fmt.Errorf("Incorrent format '%s' for engine '%s'.", r.Id(), b.inType)
|
||||
}
|
||||
|
||||
func (b convertedProcess[T]) Step(i int) bool {
|
||||
return b.process.Step(i)
|
||||
}
|
||||
Reference in New Issue
Block a user