package main
import (
"errors"
)
type attr struct{}
func (attr) Execute(args []string, ins []<-chan Datum, out chan Datum) error {
defer func() {
out <- Datum{End: true}
close(out)
}()
if len(args) == 0 {
return errors.New("usage: . <attribute> [<attribute>...]")
}
for _, d := Select(ins); d != nil; _, d = Select(ins) {
if d.End {
continue
}
if d.HTML == nil {
return errors.New("type error: expected html, got text")
}
for _, attr := range d.HTML.Attr {
for _, arg := range args[1:] {
if attr.Key == arg {
// Work around Go being shit
val := attr.Val
out <- Datum{Text: &val}
break
}
}
}
}
return nil
}
func init() {
Filters["."] = attr{}
}