Check-in [87e5dc43ff]
Overview
SHA1:87e5dc43ffd3500a384c6a0f244d52f3d68aadfa
Date: 2015-04-06 19:20:42
User: spaskalev
Comment:sync tbd
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2015-09-09
22:22
[bc1a46b4d9] initial imgui api ideas (user: spaskalev, tags: trunk)
2015-04-06
19:20
[87e5dc43ff] sync tbd (user: spaskalev, tags: trunk)
2015-03-19
20:51
[61937abf4c] Added parse.Digit and a test (user: spaskalev, tags: trunk)
Changes

Modified src/0dev.org/commands/tbd/tbd.go from [2547f40cdb] to [015d525e31].

     1         -// tbd, a #tag-based dependency tool for low ceremony task tracking
            1  +// tbd, a #tag-based dependency tool for task tracking
     2      2   package main
     3      3   
     4      4   import (
     5      5   	"bufio"
     6      6   	"bytes"
     7      7   	"fmt"
     8      8   	"io"
................................................................................
    23     23   	extract = regexp.MustCompile("(#)([^\\s]+?)(?:[,\\.\\s]|$)")
    24     24   }
    25     25   
    26     26   func main() {
    27     27   
    28     28   	var (
    29     29   		exitCode int
    30         -		handlers []handler = []handler{counting(), tracing()}
           30  +		handlers = handlerChain{counting(), tracing()}
    31     31   	)
    32     32   
    33     33   	// Parse command line elements and register handlers
    34     34   	if len(os.Args) == 1 {
    35     35   		handlers = append(handlers, cutoff())
    36     36   	} else {
    37     37   		handlers = append(handlers, matching(os.Args[1:]))
................................................................................
    58     58   		exitCode = 1
    59     59   	}
    60     60   
    61     61   	os.Exit(exitCode)
    62     62   }
    63     63   
    64     64   // Processes input through the provided handlers
    65         -func process(input io.Reader, handlers []handler) int {
           65  +func process(input io.Reader, handlers handlerChain) int {
    66     66   	reader := bufio.NewReader(input)
    67     67   	for {
    68     68   		line, err := reader.ReadString('\n')
    69     69   
    70     70   		line = strings.TrimSpace(line)
    71     71   		if len(line) > 0 {
    72         -			handle(handlers, &task{tags: parse(line), value: line})
           72  +			handlers.do(&task{tags: parse(line), value: line, depends: make(tasks, 0, 8)})
    73     73   		}
    74     74   
    75     75   		// Process errors after handling as ReadString can return both data and error f
    76     76   		if err != nil {
    77     77   			if err == io.EOF {
    78     78   				return 0
    79     79   			}
................................................................................
   147    147   	// Stop further processing of the task
   148    148   	stop bool
   149    149   }
   150    150   
   151    151   // An alias interface for all task handler functions
   152    152   type handler func(*task) action
   153    153   
          154  +// A slice of handlers
          155  +type handlerChain []handler
          156  +
   154    157   // Execute handlers against a task
   155         -func handle(handlers []handler, t *task) {
   156         -	for _, h := range handlers {
   157         -		act := h(t)
          158  +func (handlers handlerChain) do(t *task) {
          159  +	for _, current := range handlers {
          160  +		act := current(t)
   158    161   		if act.stop {
   159    162   			return
   160    163   		}
   161    164   	}
   162    165   }
   163    166   
   164    167   // Returns a counting handler closure that sets the tasks' nth field
................................................................................
   214    217   				return action{}
   215    218   			}
   216    219   		}
   217    220   		return action{stop: true}
   218    221   	}
   219    222   }
   220    223   
   221         -// Returns a handler that stores every seen task and an ancillary function to retrieve those
          224  +// Returns a handler that stores every seen task and its dependencies
          225  +//    along with an ancillary function to retrieve those in a sorted order
   222    226   func collecting() (handler, func() tasks) {
   223    227   	var seen = make(map[*task]bool)
   224    228   	return func(t *task) action {
   225    229   			depth := tasks{t}
   226    230   			for i := 0; i < len(depth); i++ {
   227    231   				if !seen[depth[i]] {
   228    232   					seen[depth[i]] = true