MCPcopy Create free account
hub / github.com/KSubedi/gomove / ProcessFileNative

Function ProcessFileNative

native.go:14–124  ·  view source on GitHub ↗
(filePath string, from string, to string)

Source from the content-addressed store, hash-verified

12)
13
14func ProcessFileNative(filePath string, from string, to string) {
15 //Colors to be used on the console
16 red := ansi.ColorCode("red+bh")
17 white := ansi.ColorCode("white+bh")
18 green := ansi.ColorCode("green+bh")
19 yellow := ansi.ColorCode("yellow+bh")
20 blackOnWhite := ansi.ColorCode("black+b:white+h")
21 //Reset the color
22 reset := ansi.ColorCode("reset")
23
24 fmt.Println(blackOnWhite+"Processing file", filePath, reset)
25
26 // Open file to read
27 fileContent, err := ioutil.ReadFile(filePath)
28 if err != nil {
29 fmt.Println(err)
30 }
31
32 // Scan file line by line
33 scanner := bufio.NewScanner(bytes.NewReader(fileContent))
34
35 // Track line that is being scanned
36 scanLine := 0
37 // Track number of changes in file
38 numChanges := 0
39
40 // Control variables
41 isImportLine := false
42
43 // Store final output text
44 output := ""
45
46 // Scan through the lines of go file
47 for scanner.Scan() {
48
49 scanLine++
50 line := scanner.Text()
51 bareLine := strings.Replace(line, " ", "", -1)
52
53 // If it is a single import statement, replace the path in that line
54 if strings.Contains(bareLine, "import\"") {
55
56 newImport := strings.Replace(line, from, to, -1)
57 output += newImport + "\n"
58 if line != newImport {
59 numChanges++
60
61 fmt.Println(red+"Updating "+
62 reset+white+
63 strings.TrimSpace(line)+
64 reset+red+
65 " to "+
66 reset+white+
67 strings.TrimSpace(newImport)+
68 reset+red+
69 "on line", scanLine, reset)
70 }
71

Callers 2

TestAppNativeFunction · 0.85
ProcessFileFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestAppNativeFunction · 0.68