mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-07 05:11:36 +08:00
Support passing arguments when using wails dev
This commit is contained in:
parent
5a30425091
commit
6ab1a4adb0
@ -3,6 +3,7 @@ package dev
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -72,7 +73,12 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer watcher.Close()
|
defer func(watcher *fsnotify.Watcher) {
|
||||||
|
err := watcher.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}(watcher)
|
||||||
|
|
||||||
var debugBinaryProcess *process.Process = nil
|
var debugBinaryProcess *process.Process = nil
|
||||||
var extensionsThatTriggerARebuild = strings.Split(extensions, ",")
|
var extensionsThatTriggerARebuild = strings.Split(extensions, ",")
|
||||||
@ -83,12 +89,18 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
|
|||||||
|
|
||||||
debounceQuit := make(chan bool, 1)
|
debounceQuit := make(chan bool, 1)
|
||||||
|
|
||||||
|
var passthruArgs []string
|
||||||
|
if len(os.Args) > 2 {
|
||||||
|
passthruArgs = os.Args[2:]
|
||||||
|
}
|
||||||
|
|
||||||
// Do initial build
|
// Do initial build
|
||||||
logger.Println("Building application for development...")
|
logger.Println("Building application for development...")
|
||||||
newProcess, err := restartApp(logger, "dev", ldflags, compilerCommand, debugBinaryProcess, loglevel)
|
newProcess, err := restartApp(logger, "dev", ldflags, compilerCommand, debugBinaryProcess, loglevel, passthruArgs)
|
||||||
if newProcess != nil {
|
if newProcess != nil {
|
||||||
debugBinaryProcess = newProcess
|
debugBinaryProcess = newProcess
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -135,7 +147,7 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
|
|||||||
// Do a rebuild
|
// Do a rebuild
|
||||||
|
|
||||||
// Try and build the app
|
// Try and build the app
|
||||||
newBinaryProcess, err := restartApp(logger, "dev", ldflags, compilerCommand, debugBinaryProcess, loglevel)
|
newBinaryProcess, err := restartApp(logger, "dev", ldflags, compilerCommand, debugBinaryProcess, loglevel, passthruArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error during build: %s", err.Error())
|
fmt.Printf("Error during build: %s", err.Error())
|
||||||
return
|
return
|
||||||
@ -224,7 +236,7 @@ exit:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func restartApp(logger *clilogger.CLILogger, outputType string, ldflags string, compilerCommand string, debugBinaryProcess *process.Process, loglevel string) (*process.Process, error) {
|
func restartApp(logger *clilogger.CLILogger, outputType string, ldflags string, compilerCommand string, debugBinaryProcess *process.Process, loglevel string, passthruArgs []string) (*process.Process, error) {
|
||||||
|
|
||||||
appBinary, err := buildApp(logger, outputType, ldflags, compilerCommand)
|
appBinary, err := buildApp(logger, outputType, ldflags, compilerCommand)
|
||||||
println()
|
println()
|
||||||
@ -247,8 +259,12 @@ func restartApp(logger *clilogger.CLILogger, outputType string, ldflags string,
|
|||||||
|
|
||||||
// TODO: Generate `backend.js`
|
// TODO: Generate `backend.js`
|
||||||
|
|
||||||
// Start up new binary
|
// Start up new binary with correct args
|
||||||
newProcess := process.NewProcess(logger, appBinary, "-loglevel", loglevel)
|
var args = []string{"-loglevel", loglevel}
|
||||||
|
if len(passthruArgs) > 0 {
|
||||||
|
args = append(args, passthruArgs...)
|
||||||
|
}
|
||||||
|
newProcess := process.NewProcess(logger, appBinary, args...)
|
||||||
err = newProcess.Start()
|
err = newProcess.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Remove binary
|
// Remove binary
|
||||||
|
Loading…
Reference in New Issue
Block a user