Add semi-functional extractor

pull/4464/head
Sharif Elgamal 2019-05-17 14:20:25 -07:00
parent 03ebb0e0f5
commit e174f3bdc6
No known key found for this signature in database
GPG Key ID: 23CC0225BD9FD702
3 changed files with 79 additions and 2 deletions
pkg/minikube
console
translate

73
hack/extract.go Normal file
View File

@ -0,0 +1,73 @@
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
var funcs []string
func main() {
paths := []string{"../pkg/minikube/", "../cmd/minikube"}
funcs = []string{"OutStyle", "ErrStyle"}
for _, f := range funcs {
for _, root := range paths {
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if strings.HasSuffix(path, ".go") {
return inspectFile(path, f)
}
return nil
})
if err != nil {
panic(err)
}
}
}
}
func inspectFile(filename string, f string) error {
fset := token.NewFileSet()
r, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
//fmt.Printf("Parsing %s\n", filename)
file, err := parser.ParseFile(fset, "", r, parser.ParseComments)
if err != nil {
return err
}
ast.Inspect(file, func(x ast.Node) bool {
fd, ok := x.(*ast.FuncDecl)
if !ok {
return true
}
fmt.Println(fd.Name)
for _, stmt := range fd.Body.List {
fmt.Printf(" %s\n", stmt)
/*if !ok {
return true
}
if strings.Contains(fmt.Sprintf("%s", s.Fun), f) {
argString := fmt.Sprintf("%s", s.Args[1])
if strings.Contains(argString, "\"") {
fmt.Printf("%s\n", argString[strings.Index(argString, "\""):strings.LastIndex(argString, "\"")+1])
} else {
funcs = append(funcs)
}
}*/
}
return true
})
return nil
}

View File

@ -78,7 +78,7 @@ func OutStyle(style, format string, a ...interface{}) {
// Out writes a basic formatted string to stdout
func Out(format string, a ...interface{}) {
p := message.NewPrinter(preferredLanguage)
p := message.NewPrinter(translate.GetPreferredLanguage())
if outFile == nil {
glog.Errorf("no output file has been set")
return
@ -110,7 +110,7 @@ func ErrStyle(style, format string, a ...interface{}) {
// Err writes a basic formatted string to stderr
func Err(format string, a ...interface{}) {
p := message.NewPrinter(preferredLanguage)
p := message.NewPrinter(translate.GetPreferredLanguage())
if errFile == nil {
glog.Errorf("no error file has been set")
return

View File

@ -42,6 +42,10 @@ var (
// Translate translates the given string to the supplied langauge.
func Translate(s string) string {
if preferredLanguage == defaultLanguage {
return s
}
if len(Translations) == 0 {
return s
}