From aadf030096b68f14a3cc52f648846c281f535b08 Mon Sep 17 00:00:00 2001 From: Kaushal Subedi Date: Mon, 26 Oct 2015 21:58:51 -0600 Subject: minor fixes --- ast.go | 28 ++++++++++++++-------------- native.go | 10 +++++----- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ast.go b/ast.go index d2e4e93..b71abcf 100644 --- a/ast.go +++ b/ast.go @@ -19,14 +19,12 @@ func ProcessFileAST(filePath string, from string, to string) { //Colors to be used on the console red := ansi.ColorCode("red+bh") white := ansi.ColorCode("white+bh") - greenUnderline := ansi.ColorCode("green+buh") + yellow := ansi.ColorCode("yellow+bh") blackOnWhite := ansi.ColorCode("black+b:white+h") //Reset the color reset := ansi.ColorCode("reset") - fmt.Println(blackOnWhite + - "RUNNING IN SAFE MODE" + - reset) + fmt.Println(blackOnWhite+"Processing file", filePath, "in SAFE MODE", reset) // New FileSet to parse the go file to fSet := token.NewFileSet() @@ -47,7 +45,7 @@ func ProcessFileAST(filePath string, from string, to string) { for _, mPackage := range imports { for _, mImport := range mPackage { // Since astutil returns the path string with quotes, remove those - importString := mImport.Path.Value + importString := strings.TrimSuffix(strings.TrimPrefix(mImport.Path.Value, "\""), "\"") // If the path matches the oldpath, replace it with the new one if strings.Contains(importString, from) { @@ -59,10 +57,8 @@ func ProcessFileAST(filePath string, from string, to string) { fmt.Println(red + "Updating import " + - importString + - " from file " + reset + white + - filePath + + importString + reset + red + " to " + reset + white + @@ -83,12 +79,16 @@ func ProcessFileAST(filePath string, from string, to string) { printer.Fprint(&outputBuffer, fSet, file) ioutil.WriteFile(filePath, outputBuffer.Bytes(), os.ModePerm) - fmt.Printf(blackOnWhite+ - "File "+ - filePath+ - " saved after %d changes."+ - reset+"\n", numChanges) + fmt.Println(yellow+ + "File", + filePath, + "saved after", + numChanges, + "changes", + reset, "\n\n") } else { - fmt.Println(greenUnderline + "No changes needed on file " + filePath + reset) + fmt.Println(yellow+ + "No changes to write on this file.", + reset, "\n\n") } } diff --git a/native.go b/native.go index eed2346..92be282 100644 --- a/native.go +++ b/native.go @@ -35,7 +35,7 @@ func ProcessFileNative(filePath string, from string, to string) { // Track line that is being scanned scanLine := 0 // Track number of changes in file - numChages := 0 + numChanges := 0 // Control variables isImportLine := false @@ -56,7 +56,7 @@ func ProcessFileNative(filePath string, from string, to string) { newImport := strings.Replace(line, from, to, -1) output += newImport + "\n" if line != newImport { - numChages++ + numChanges++ fmt.Println(red+"Updating "+ reset+white+ @@ -86,7 +86,7 @@ func ProcessFileNative(filePath string, from string, to string) { newImport := strings.Replace(line, from, to, -1) output += newImport + "\n" if line != newImport { - numChages++ + numChanges++ fmt.Println(red+"Updating text "+ reset+white+ strings.TrimSpace(line)+ @@ -107,12 +107,12 @@ func ProcessFileNative(filePath string, from string, to string) { } // Only write if changes were made - if numChages > 0 { + if numChanges > 0 { fmt.Println(yellow+ "File", filePath, "saved after", - numChages, + numChanges, "changes", reset, "\n\n") ioutil.WriteFile(filePath, []byte(output), os.ModePerm) -- cgit v1.2.3