|
I want to get cli arguments. for example:
package main
import (
"context"
"embed"
// "fmt"
"os"
"strings"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
)
//go:embed all:frontend/dist
var assets embed.FS
func main() {
app := &App{}
// if len(os.Args) < 2 {
// panic(fmt.Sprintf("Missing args: ", os.Args))
// }
app.path = strings.Join(os.Args, "+")
println(app.path)
err := wails.Run(&options.App{
Title: "get-cli",
Width: 1024,
Height: 768,
AssetServer: &assetserver.Options{
Assets: assets,
},
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
OnStartup: app.startup,
Bind: []interface{}{
app,
},
})
if err != nil {
println("Error:", err.Error())
}
}
type App struct {
ctx context.Context
path string
}
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
// Greet returns a greeting for the given name
func (a *App) GetCliArgs() string {
return a.path
}
import { GetCliArgs } from '../wailsjs/go/main/App';
GetCliArgs().then((res) => {
document.querySelector('#app')!.innerHTML = res;
});
$ wails dev -appargs "arg"
Wails CLI v2.10.1
Executing: go mod tidy
• Generating bindings: 2025/03/29 11:33:43 /tmp/wailsbindings
Done.
• Installing frontend dependencies: Done.
• Compiling frontend: Done.At first glance, it seems that the app can get arguments successfully. But if these statements are uncommented, it seems that apps cannot get arguments. // main.go
// uncomments here:
if len(os.Args) < 2 {
panic(fmt.Sprintf("Missing args: ", os.Args))
}# shell
$ wails dev -appargs "arg"
Wails CLI v2.10.1
Executing: go mod tidy
• Generating bindings:
ERROR
panic: Missing args: %!(EXTRA []string=[/tmp/wailsbindings])
goroutine 1 [running]:
main.main()
/home/xxx/xxx/get-cli/main.go:23 +0x2fa
exit status 2
♥ If Wails is useful to you or your company, please consider sponsoring the project:
https://github.com/sponsors/leaanthonyEven $ wails build
Wails CLI v2.10.1
# Build Options
Platform(s) | linux/amd64
Compiler | /usr/bin/go
Skip Bindings | false
Build Mode | production
Devtools | false
Frontend Directory | /home/xxx/xxx/get-cli/frontend
Obfuscated | false
Skip Frontend | false
Compress | false
Package | true
Clean Bin Dir | false
LDFlags |
Tags | []
Race Detector | false
# Building target: linux/amd64
• Generating bindings: ERROR
panic: Missing args: %!(EXTRA []string=[/tmp/wailsbindings])
goroutine 1 [running]:
main.main()
/home/xxx/xxx/get-cli/main.go:23 +0x2fa
exit status 2
ERROR
panic: Missing args: %!(EXTRA []string=[/tmp/wailsbindings])
goroutine 1 [running]:
main.main()
/home/xxx/xxx/get-cli/main.go:23 +0x2fa
exit status 2
♥ If Wails is useful to you or your company, please consider sponsoring the project:
https://github.com/sponsors/leaanthonyHow can I get cli arguments just after building? And when are the arguments passed? |
Replies: 1 comment
|
kron6876 has helped me in official discord sarver. here is his/her solution:
|

kron6876 has helped me in official discord sarver.
here is his/her solution: