-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·96 lines (74 loc) · 1.75 KB
/
main.go
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
94
95
96
package main
import (
"log"
"time"
"github.com/GreenRaccoon23/rp/cmd"
"github.com/GreenRaccoon23/rp/futil"
"github.com/GreenRaccoon23/rp/globber"
"github.com/GreenRaccoon23/rp/logger"
"github.com/GreenRaccoon23/rp/replacer"
)
var (
fpaths []string
)
func init() {
cmd.Parse()
setLogger()
setFpaths()
}
func main() {
// debug()
// os.Exit(0)
start := time.Now()
edited, err := rp()
if err != nil {
log.Fatal(err)
}
logger.Report(edited, start)
}
func setLogger() {
verbose := cmd.Verbose
quiet := cmd.Quiet
logger.SetIntensity(verbose, quiet)
}
func setFpaths() {
rpaths := cmd.Rpaths
inclusions := cmd.Inclusions
exclusions := cmd.Exclusions
recursive := cmd.Recursive
g := globber.New(rpaths, inclusions, exclusions, recursive)
matches, err := g.Glob()
if err != nil {
log.Fatal(err)
}
hardlinks := futil.Hardlinks(matches)
fpaths = hardlinks
}
func rp() (int, error) {
toFind := cmd.ToFind
toReplace := cmd.ToReplace
regex := cmd.Regex
concurrency := cmd.Concurrency
list := cmd.List
commit := !list
r := replacer.New(toFind, toReplace, regex, commit)
edited, err := r.Edit(fpaths, concurrency)
if err != nil {
return 0, err
}
return edited, nil
}
// func debug() {
//
// fmt.Printf("cmd.ToFind: %v\n", cmd.ToFind)
// fmt.Printf("cmd.ToReplace: %v\n", cmd.ToReplace)
// fmt.Printf("cmd.Regex: %v\n", cmd.Regex)
// fmt.Printf("cmd.Recursive: %v\n", cmd.Recursive)
// fmt.Printf("cmd.Inclusions: %v\n", cmd.Inclusions)
// fmt.Printf("cmd.Exclusions: %v\n", cmd.Exclusions)
// fmt.Printf("cmd.Concurrency: %v\n", cmd.Concurrency)
// fmt.Printf("cmd.List: %v\n", cmd.List)
// fmt.Printf("cmd.Verbose: %v\n", cmd.Verbose)
// fmt.Printf("cmd.Quiet: %v\n", cmd.Quiet)
// fmt.Printf("fpaths: %v\n", fpaths)
// }