-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
93 lines (82 loc) · 3.54 KB
/
main.go
File metadata and controls
93 lines (82 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"fmt"
"os"
"regexp"
"github.com/akamensky/argparse"
logging "github.com/op/go-logging"
"github.com/mathpn/listme/pretty"
"github.com/mathpn/listme/search"
)
var log = logging.MustGetLogger("listme")
var format = logging.MustStringFormatter(`%{color}%{level}%{color:reset}: %{message}`)
var tags = []string{"BUG", "FIXME", "XXX", "TODO", "HACK", "OPTIMIZE", "NOTE"}
var tagValRegex = regexp.MustCompile(`^(\w+)$`)
func validateTags(tags []string) error {
for _, tag := range tags {
match := tagValRegex.MatchString(tag)
if !match {
return fmt.Errorf("provided tags must be non-empty and contain only alphanumeric characters")
}
}
return nil
}
func main() {
parser := argparse.NewParser("listme", "Summarize you FIXME, TODO, XXX (and other tags) comments so you don't forget them.")
path := parser.StringPositional(&argparse.Options{Help: "Path to folder or file to be searched. Search is recursive."})
tags := parser.StringList("T", "tags", &argparse.Options{Default: tags, Validate: validateTags, Help: "Tags to search for, input should be separated by spaces"})
glob := parser.String("g", "glob", &argparse.Options{Default: "*", Help: "Glob pattern to filter files in the search. Use a single-quoted string. Example: '*.go'"})
author := parser.String("a", "author", &argparse.Options{Help: "Filter lines by commit author"})
ageFilter := parser.Int("n", "newer-than", &argparse.Options{Default: -1, Help: "Filters lines based on the age of commits, showing only lines committed within the specified number of days"})
oldCommitLimit := parser.Int("o", "old-commit-mark-limit", &argparse.Options{Default: 60, Help: "Sets the age limit for marking commits as old, with commits older than the specified limit being marked"})
maxFileSize := parser.Int("f", "max-file-size", &argparse.Options{Default: 5, Help: "Maximum file size to scan (in MB)"})
fullPath := parser.Flag("F", "full-path", &argparse.Options{Help: "Print full absolute path of the files"})
noAuthor := parser.Flag("A", "no-author", &argparse.Options{Help: "Do not print git author information"})
noSummary := parser.Flag("S", "no-summary", &argparse.Options{Help: "Do not print summary box for each file"})
bw := parser.Flag("b", "bw", &argparse.Options{Help: "Use black and white style"})
plain := parser.Flag("p", "plain", &argparse.Options{Help: "Use plain style. Ideal for machine consumption. Used by default when redirecting the output"})
workers := parser.Int("w", "workers", &argparse.Options{Default: 128, Help: "[debug] Number of search workers. There's likely no need to change this"})
verbose := parser.Flag("v", "verbose", &argparse.Options{Help: "Enable info logging level"})
debug := parser.Flag("d", "debug", &argparse.Options{Help: "Add debug verbosity"})
err := parser.Parse(os.Args)
if err != nil {
fmt.Print(parser.Usage(err))
panic(err)
}
if *maxFileSize <= 0 {
panic("max-file-size must be a positive integer")
}
logging.SetFormatter(format)
b := logging.NewLogBackend(os.Stderr, "", 0)
bFormatter := logging.NewBackendFormatter(b, format)
logging.SetBackend(bFormatter)
logging.SetLevel(logging.WARNING, "")
if *verbose {
logging.SetLevel(logging.INFO, "")
}
if *debug {
logging.SetLevel(logging.DEBUG, "")
}
style, err := pretty.GetStyle(*bw, *plain)
if err != nil {
log.Fatal(err)
}
params, err := search.NewSearchParams(
*path,
*tags,
*workers,
style,
*oldCommitLimit,
*ageFilter,
int64(*maxFileSize),
*fullPath,
*noSummary,
*noAuthor,
*glob,
*author,
)
if err != nil {
log.Fatal(err)
}
search.Search(params)
}