Index: src/0dev.org/commands/tbd/tbd.go ================================================================== --- src/0dev.org/commands/tbd/tbd.go +++ src/0dev.org/commands/tbd/tbd.go @@ -1,6 +1,6 @@ -// tbd, a #tag-based dependency tool for low ceremony task tracking +// tbd, a #tag-based dependency tool for task tracking package main import ( "bufio" "bytes" @@ -25,11 +25,11 @@ func main() { var ( exitCode int - handlers []handler = []handler{counting(), tracing()} + handlers = handlerChain{counting(), tracing()} ) // Parse command line elements and register handlers if len(os.Args) == 1 { handlers = append(handlers, cutoff()) @@ -60,18 +60,18 @@ os.Exit(exitCode) } // Processes input through the provided handlers -func process(input io.Reader, handlers []handler) int { +func process(input io.Reader, handlers handlerChain) int { reader := bufio.NewReader(input) for { line, err := reader.ReadString('\n') line = strings.TrimSpace(line) if len(line) > 0 { - handle(handlers, &task{tags: parse(line), value: line}) + handlers.do(&task{tags: parse(line), value: line, depends: make(tasks, 0, 8)}) } // Process errors after handling as ReadString can return both data and error f if err != nil { if err == io.EOF { @@ -149,14 +149,17 @@ } // An alias interface for all task handler functions type handler func(*task) action +// A slice of handlers +type handlerChain []handler + // Execute handlers against a task -func handle(handlers []handler, t *task) { - for _, h := range handlers { - act := h(t) +func (handlers handlerChain) do(t *task) { + for _, current := range handlers { + act := current(t) if act.stop { return } } } @@ -216,11 +219,12 @@ } return action{stop: true} } } -// Returns a handler that stores every seen task and an ancillary function to retrieve those +// Returns a handler that stores every seen task and its dependencies +// along with an ancillary function to retrieve those in a sorted order func collecting() (handler, func() tasks) { var seen = make(map[*task]bool) return func(t *task) action { depth := tasks{t} for i := 0; i < len(depth); i++ {