[v2] Tags passthrough for wails generate module

This commit is contained in:
Lea Anthony
2021-10-09 07:56:19 +11:00
parent 1368c20029
commit cad1317fc8
3 changed files with 29 additions and 15 deletions

View File

@@ -120,7 +120,11 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
return err
}
err = runCommand(cwd, true, "wails", "generate", "module")
if flags.tags != "" {
err = runCommand(cwd, true, "wails", "generate", "module", "-tags", flags.tags)
} else {
err = runCommand(cwd, true, "wails", "generate", "module")
}
if err != nil {
return err
}
@@ -134,7 +138,7 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
buildOptions := generateBuildOptions(flags)
buildOptions.Logger = logger
buildOptions.UserTags = parseUserTags(flags.tags)
buildOptions.UserTags = internal.ParseUserTags(flags.tags)
var debugBinaryProcess *process.Process = nil
@@ -266,18 +270,6 @@ func generateBuildOptions(flags devFlags) *build.Options {
}
}
// parseUserTags takes the string form of tags and converts to a slice of strings
func parseUserTags(tagString string) []string {
userTags := make([]string, 0)
for _, tag := range strings.Split(tagString, " ") {
thisTag := strings.TrimSpace(tag)
if thisTag != "" {
userTags = append(userTags, thisTag)
}
}
return userTags
}
// loadAndMergeProjectConfig reconciles flags passed to the CLI with project config settings and updates
// the project config if necessary
func loadAndMergeProjectConfig(cwd string, flags *devFlags) (*project.Project, error) {

View File

@@ -2,17 +2,21 @@ package generate
import (
"github.com/leaanthony/clir"
"github.com/wailsapp/wails/v2/cmd/wails/internal"
"github.com/wailsapp/wails/v2/internal/shell"
"io"
"os"
"path/filepath"
"runtime"
"strings"
)
// AddModuleCommand adds the `module` subcommand for the `generate` command
func AddModuleCommand(app *clir.Cli, parent *clir.Command, w io.Writer) error {
command := parent.NewSubCommand("module", "Generate wailsjs modules")
var tags string
command.StringFlag("tags", "tags to pass to Go compiler (quoted and space separated)", &tags)
command.Action(func() error {
@@ -29,7 +33,10 @@ func AddModuleCommand(app *clir.Cli, parent *clir.Command, w io.Writer) error {
return err
}
_, _, err = shell.RunCommand(cwd, "go", "build", "-tags", "bindings", "-o", filename)
tagList := internal.ParseUserTags(tags)
tagList = append(tagList, "bindings")
_, _, err = shell.RunCommand(cwd, "go", "build", "-tags", strings.Join(tagList, ","), "-o", filename)
if err != nil {
return err
}

View File

@@ -0,0 +1,15 @@
package internal
import "strings"
// ParseUserTags takes the string form of tags and converts to a slice of strings
func ParseUserTags(tagString string) []string {
userTags := make([]string, 0)
for _, tag := range strings.Split(tagString, " ") {
thisTag := strings.TrimSpace(tag)
if thisTag != "" {
userTags = append(userTags, thisTag)
}
}
return userTags
}