Skip to content

Commit

Permalink
[asthelpergen] Migrate to pflags (#11363)
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <andres@planetscale.com>

Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay authored Sep 27, 2022
1 parent 6da641a commit 60325f3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 28 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ visitor: asthelpergen
echo "make visitor has been replaced by make asthelpergen"

asthelpergen:
go run ./go/tools/asthelpergen/main -in ./go/vt/sqlparser -iface vitess.io/vitess/go/vt/sqlparser.SQLNode -except "*ColName"
go run ./go/tools/asthelpergen/main \
--in ./go/vt/sqlparser \
--iface vitess.io/vitess/go/vt/sqlparser.SQLNode \
--except "*ColName"

sizegen:
go run ./go/tools/sizegen/sizegen.go \
Expand Down
13 changes: 0 additions & 13 deletions go/tools/asthelpergen/asthelpergen.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,6 @@ func (gen *astHelperGen) GenerateCode() (map[string]*jen.File, error) {
return result, nil
}

// TypePaths are the packages
type TypePaths []string

func (t *TypePaths) String() string {
return fmt.Sprintf("%v", *t)
}

// Set adds the package path
func (t *TypePaths) Set(path string) error {
*t = append(*t, path)
return nil
}

// VerifyFilesOnDisk compares the generated results from the codegen against the files that
// currently exist on disk and returns any mismatches
func VerifyFilesOnDisk(result map[string]*jen.File) (errors []error) {
Expand Down
29 changes: 16 additions & 13 deletions go/tools/asthelpergen/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,36 @@ limitations under the License.
package main

import (
"flag"
"log"
"os"

"vitess.io/vitess/go/tools/goimports"
"github.com/spf13/pflag"

"vitess.io/vitess/go/tools/asthelpergen"

. "vitess.io/vitess/go/tools/asthelpergen"
"vitess.io/vitess/go/tools/goimports"
)

func main() {
var patterns TypePaths
var generate, except string
var verify bool
var (
patterns []string
generate, except string
verify bool
)

flag.Var(&patterns, "in", "Go packages to load the generator")
flag.StringVar(&generate, "iface", "", "Root interface generate rewriter for")
flag.BoolVar(&verify, "verify", false, "ensure that the generated files are correct")
flag.StringVar(&except, "except", "", "don't deep clone these types")
flag.Parse()
pflag.StringSliceVar(&patterns, "in", nil, "Go packages to load the generator")
pflag.StringVar(&generate, "iface", "", "Root interface generate rewriter for")
pflag.BoolVar(&verify, "verify", false, "ensure that the generated files are correct")
pflag.StringVar(&except, "except", "", "don't deep clone these types")
pflag.Parse()

result, err := GenerateASTHelpers(patterns, generate, except)
result, err := asthelpergen.GenerateASTHelpers(patterns, generate, except)
if err != nil {
log.Fatal(err)
}

if verify {
for _, err := range VerifyFilesOnDisk(result) {
for _, err := range asthelpergen.VerifyFilesOnDisk(result) {
log.Fatal(err)
}
log.Printf("%d files OK", len(result))
Expand Down
2 changes: 1 addition & 1 deletion misc/git/hooks/asthelpers
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@

# this script, which should run before committing code, makes sure that the visitor is re-generated when the ast changes

go run ./go/tools/asthelpergen/main -in ./go/vt/sqlparser -verify=true -iface vitess.io/vitess/go/vt/sqlparser.SQLNode -except "*ColName"
go run ./go/tools/asthelpergen/main --in ./go/vt/sqlparser --verify=true --iface vitess.io/vitess/go/vt/sqlparser.SQLNode --except "*ColName"

0 comments on commit 60325f3

Please sign in to comment.