Add find
command
Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
parent
0a6e2b075c
commit
97445ca2cd
3 changed files with 69 additions and 0 deletions
|
@ -43,6 +43,39 @@ func GetAllZets(dir string) []int {
|
|||
return sorted
|
||||
}
|
||||
|
||||
func SearchZets(dir string, query string) []int {
|
||||
zets, err := execGitCommand(dir, "grep", "-i", "--name-only", "--word-regex", query)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("No matches found for %s.\n", query)
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
re := regexp.MustCompile(`[0-9]+`)
|
||||
matches := re.FindAllString(zets, -1)
|
||||
|
||||
sort.Strings(matches)
|
||||
|
||||
ids := make(map[int]struct{})
|
||||
for _, id := range matches {
|
||||
num, err := strconv.Atoi(id)
|
||||
|
||||
if err == nil {
|
||||
ids[num] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
var sorted []int
|
||||
for num := range ids {
|
||||
sorted = append(sorted, num)
|
||||
}
|
||||
|
||||
sort.Ints(sorted)
|
||||
|
||||
return sorted
|
||||
}
|
||||
|
||||
func ParseZetList(ids []int) []string {
|
||||
var lines []string
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue