Skip to content

Commit

Permalink
Addressed sanjay's comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrandl committed Sep 6, 2024
1 parent f3711d8 commit 12931f8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
14 changes: 4 additions & 10 deletions cmd/weaver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,19 @@ func main() {
switch flag.Arg(0) {
case "generate":
generateFlags := flag.NewFlagSet("generate", flag.ExitOnError)
tags := generateFlags.String("tags", "not specified", "Optional tags for the generate command")
tags := generateFlags.String("tags", "", "Optional tags for the generate command")
generateFlags.Usage = func() {
fmt.Fprintln(os.Stderr, generate.Usage)
}
generateFlags.Parse(flag.Args()[1:])
buildTags := "--tags=ignoreWeaverGen"
if *tags != "not specified" { // tags flag was specified
if *tags == "" || *tags == "." {
// User specified the tags flag but didn't provide any tags.
fmt.Fprintln(os.Stderr, "No tags provided.")
os.Exit(1)
}
buildTags := "ignoreWeaverGen"
if *tags != "" { // tags flag was specified
// TODO(rgrandl): we assume that the user specify the tags properly. I.e.,
// a single tag, or a list of tags separated by comma. We may want to do
// extra validation at some point.
buildTags = buildTags + "," + *tags
}
idx := len(flag.Args()) - len(generateFlags.Args())
if err := generate.Generate(".", flag.Args()[idx:], generate.Options{BuildTags: buildTags}); err != nil {
if err := generate.Generate(".", generateFlags.Args(), generate.Options{BuildTags: buildTags}); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/tool/generate/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const (
Usage = `Generate code for a Service Weaver application.
Usage:
weaver generate [tags] [packages]
weaver generate [-tags taglist] [packages]
Description:
"weaver generate" generates code for the Service Weaver applications in the
Expand Down Expand Up @@ -121,7 +121,7 @@ func Generate(dir string, pkgs []string, opt Options) error {
ParseFile: parseNonWeaverGenFile,
}
if len(opt.BuildTags) > 0 {
cfg.BuildFlags = []string{opt.BuildTags}
cfg.BuildFlags = []string{"-tags", opt.BuildTags}
}
pkgList, err := packages.Load(cfg, pkgs...)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/tool/generate/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func runGenerator(t *testing.T, directory, filename, contents string, subdirs []
// Run "weaver generate".
opt := Options{
Warn: func(err error) { t.Log(err) },
BuildTags: "--tags=ignoreWeaverGen",
BuildTags: "ignoreWeaverGen",
}
if err := Generate(tmp, []string{tmp}, opt); err != nil {
return "", err
Expand Down Expand Up @@ -295,7 +295,7 @@ func TestGeneratorBuildWithTags(t *testing.T) {
// Run the "weaver generate" command with the build tag "good". Verify that the
// command succeeds because the bad.go file is ignored, and the weaver_gen.go
// contains only generated code for the good.go.
err = Generate(tmp, []string{tmp}, Options{Warn: func(err error) { t.Log(err) }, BuildTags: "--tags=good"})
err = Generate(tmp, []string{tmp}, Options{Warn: func(err error) { t.Log(err) }, BuildTags: "good"})
if err != nil {
t.Fatalf("unexpected generator error: %v", err)
}
Expand Down

0 comments on commit 12931f8

Please sign in to comment.