nix-amer/internal/instruction/alias.go

38 lines
605 B
Go

package instruction
import (
"strings"
)
type alias struct {
raw string
// Name of the alias
Name string
// Value to resolve to
Value string
}
func (d *alias) Raw() string { return strings.Join([]string{"alias", d.raw}, " ") }
func (d *alias) Build(_args string) error {
// 1. extract action fields ()
split := strings.SplitN(_args, " ", 2)
// 2. check syntax
if len(split) != 2 {
return ErrInvalidSyntax
}
d.Name = split[0]
d.Value = split[1]
d.raw = _args
return nil
}
func (d alias) Exec(ctx ExecutionContext) ([]byte, error) {
ctx.Alias[d.Name] = d.Value
return nil, nil
}