diff --git a/internal/instruction/alias.go b/internal/instruction/alias.go new file mode 100644 index 0000000..0e3706c --- /dev/null +++ b/internal/instruction/alias.go @@ -0,0 +1,37 @@ +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 +} diff --git a/internal/instruction/reader.go b/internal/instruction/reader.go index 958ca1a..ad059d0 100644 --- a/internal/instruction/reader.go +++ b/internal/instruction/reader.go @@ -40,6 +40,10 @@ func Parse(raw string) (T, error) { i := &set{} err := i.Build(split[1]) return i, err + case "alias": + i := &alias{} + err := i.Build(split[1]) + return i, err default: return nil, ErrUnknownInstruction }