github.com/driusan/bug@v0.3.2-0.20190306121946-d7f4e7f33fea/bugapp/Find.go (about)

     1  package bugapp
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/driusan/bug/bugs"
     6  	"io/ioutil"
     7  	"os"
     8  )
     9  
    10  func find(findType string, findValues []string) {
    11  	issues, _ := ioutil.ReadDir(string(bugs.GetIssuesDir()))
    12  	for idx, issue := range issues {
    13  		if issue.IsDir() != true {
    14  			continue
    15  		}
    16  		var dir bugs.Directory = bugs.GetIssuesDir() + bugs.Directory(issue.Name())
    17  		b := bugs.Bug{Dir: dir}
    18  		name := getBugName(b, idx)
    19  		var values []string
    20  		switch findType {
    21  		case "tags":
    22  			values = b.StringTags()
    23  		case "status":
    24  			values = []string{b.Status()}
    25  		case "priority":
    26  			values = []string{b.Priority()}
    27  		case "milestone":
    28  			values = []string{b.Milestone()}
    29  		default:
    30  			fmt.Printf("Unknown find type: %s\n", findType)
    31  			return
    32  		}
    33  		printed := false
    34  		for _, findValue := range findValues {
    35  			for _, value := range values {
    36  				if value == findValue {
    37  					fmt.Printf("%s: %s\n", name, b.Title(findType))
    38  					printed = true
    39  				}
    40  			}
    41  			if printed {
    42  				break
    43  			}
    44  		}
    45  	}
    46  }
    47  
    48  func Find(args ArgumentList) {
    49  	if len(args) < 2 {
    50  		fmt.Printf("Usage: %s find {tag, status, priority, milestone} value1 [value2 ...]\n", os.Args[0])
    51  		return
    52  	}
    53  	switch args[0] {
    54  	case "tags":
    55  		fallthrough
    56  	case "status":
    57  		fallthrough
    58  	case "priority":
    59  		fallthrough
    60  	case "milestone":
    61  		find(args[0], args[1:])
    62  	default:
    63  		fmt.Printf("Unknown command: %s %s %s\n", os.Args[0], os.Args[1], os.Args[2])
    64  		return
    65  	}
    66  }