From 579745b6634c4195c3bc071941c0870dd1bfa129 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 16 Oct 2025 09:01:11 -0500 Subject: automation using the excellent 'goimports' tool --- doProto.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'doProto.go') diff --git a/doProto.go b/doProto.go index 579865c..4be9c1d 100644 --- a/doProto.go +++ b/doProto.go @@ -26,7 +26,7 @@ import ( "go.wit.com/log" ) -func doProto(argvProto string) error { +func doProto(argvProto string) (string, error) { pf := new(File) me.pb.Files = append(me.pb.Files, pf) pf.Filename = argvProto @@ -196,8 +196,27 @@ func doProto(argvProto string) error { badExit(err) } } - log.Info("") - log.Info("you may have to run 'goimport -w *.go' on the new *pb.go files") - log.Info("") - return nil + var err error + if err == nil { + // run goimports to clean the autogenpb files up + globPattern := pf.Filebase + "*.pb.go" + var files []string + files, err = filepath.Glob(globPattern) + if err != nil { + log.Info("glob error", err, files) + } + if len(files) == 0 { + // something went wrong + err = errors.New("autogenpb failed to create *.pb.go files") + } else { + cmd := []string{"goimports", "-w"} + cmd = append(cmd, files...) + log.Info("Running:", cmd) + shell.RunVerbose(cmd) + } + } + if err == nil { + return "autogenpb worked", nil + } + return "autogenpb failed", err } -- cgit v1.2.3