github.com/grantbow/fit@v0.7.1-0.20220916164603-1f7c88ac81e6/fitapp/Find.go (about)

     1  package fitapp
     2  
     3  import (
     4  	"fmt"
     5  	bugs "github.com/grantbow/fit/issues"
     6  	"os"
     7  	"sort"
     8  )
     9  
    10  //var dops = bugs.Directory(os.PathSeparator)
    11  //var sops = string(os.PathSeparator)
    12  
    13  // find does the work of finding bugs.
    14  func find(findType string, findValues []string, config bugs.Config) {
    15  	fitdir := bugs.FitDirer(config)
    16  	//issues, _ := ioutil.ReadDir(string(fitdir))
    17  	issues := readIssues(string(fitdir))
    18  	sort.Sort(byDir(issues))
    19  	for idx, issue := range issues {
    20  		var dir bugs.Directory = fitdir + dops + bugs.Directory(issue.Name())
    21  		b := bugs.Issue{Dir: dir}
    22  		name := issueNamer(b, idx)
    23  		var values []string
    24  		switch findType {
    25  		case "tags":
    26  			values = b.StringTags()
    27  		case "status":
    28  			values = []string{b.Status()}
    29  		case "priority":
    30  			values = []string{b.Priority()}
    31  		case "milestone":
    32  			values = []string{b.Milestone()}
    33  		default:
    34  			fmt.Printf("Unknown find type: %s\n", findType)
    35  			return
    36  		}
    37  		printed := false
    38  		for _, findValue := range findValues {
    39  			for _, value := range values {
    40  				if value == findValue {
    41  					fmt.Printf("%s: %s\n", name, b.Title(findType))
    42  					printed = true
    43  				}
    44  			}
    45  			if printed {
    46  				break
    47  			}
    48  		}
    49  	}
    50  }
    51  
    52  // Find is a subcommand to find issues.
    53  func Find(args argumentList, config bugs.Config) {
    54  	if len(args) < 2 {
    55  		fmt.Printf("Usage: %s find {tags, status, priority, milestone} value1 [value2 ...]\n", os.Args[0])
    56  		return
    57  	}
    58  	switch args[0] {
    59  	case "tags":
    60  		fallthrough
    61  	case "status":
    62  		fallthrough
    63  	case "priority":
    64  		fallthrough
    65  	case "milestone":
    66  		find(args[0], args[1:], config)
    67  	default:
    68  		fmt.Printf("Unknown command: %v\n", args)
    69  		return
    70  	}
    71  }