-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (37 loc) · 707 Bytes
/
main.go
File metadata and controls
50 lines (37 loc) · 707 Bytes
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
package main
import (
"flag"
"fmt"
"os"
)
func main() {
var fFile = flag.String("f", "", "file path")
flag.Parse()
if fFile == nil || *fFile == "" {
panic("file path (-f) is required")
}
rules := flag.Args()
fmt.Println(rules)
file, err := os.ReadFile(*fFile)
if err != nil {
panic(err)
}
text := string(file)
replacers := []Replacer{}
for _, rule := range rules {
replacer, err := GetReplacers(rule)
if err != nil {
panic(err)
}
replacers = append(replacers, replacer)
}
new_text := text
for _, r := range replacers {
new_text = ApplyReplacer(r, new_text)
}
f, err := os.Create("./output.txt")
if err != nil {
panic(err)
}
f.Write([]byte(new_text))
}