cmd: allow to provide custom functions for export

As an example for the frostfs-node:
```
go run ./cmd -funcs reportFlushError,reportError ../node
```

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-03-17 18:57:11 +03:00 committed by Evgenii Stratonikov
parent e232bfeef4
commit 72a7b2eca0

View file

@ -1,6 +1,7 @@
package main
import (
"flag"
"fmt"
"go/ast"
"go/parser"
@ -8,14 +9,21 @@ import (
"log"
"os"
"path/filepath"
"strings"
)
var (
customLogs = flag.String("funcs", "", "Custom functions to export delimited by ','.")
)
func main() {
if len(os.Args) != 2 {
flag.Parse()
if flag.NArg() != 1 {
log.Fatalln("directory must be provided")
}
directories, err := getAllSubdirectories(os.Args[1])
directories, err := getAllSubdirectories(flag.Arg(0))
if err != nil {
log.Fatalf("failed to list subdirs: %v", err)
}
@ -78,7 +86,27 @@ func isLogDot(expr ast.Expr) bool {
return ok && (isIdent(sel.Sel, "Debug") ||
isIdent(sel.Sel, "Info") ||
isIdent(sel.Sel, "Warn") ||
isIdent(sel.Sel, "Error"))
isIdent(sel.Sel, "Error") ||
isCustomLog(sel.Sel))
}
func isCustomLog(expr ast.Expr) bool {
id, ok := expr.(*ast.Ident)
if !ok {
return false
}
if len(*customLogs) == 0 {
return false
}
ss := strings.Split(*customLogs, ",")
for i := range ss {
if id.Name == ss[i] {
return true
}
}
return false
}
func isIdent(expr ast.Expr, ident string) bool {