Repository navigation
Update CLI to pass through variables - #4488
Conversation
- Modified build and package commands to accept otherArgs parameter - Updated task wrapper to forward CLI variables to Task - Enhanced task.go to properly parse and handle CLI variables (KEY=VALUE format) - Fixes issue where 'wails3 build' and 'wails3 package' commands weren't forwarding parameters Fixes #4422
WalkthroughThis update adds comprehensive documentation for passing CLI variables to tasks and refines the CLI subcommands Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI (wails3)
participant Task Wrapper
participant Task Executor
User->>CLI (wails3): wails3 build KEY=VALUE
CLI (wails3)->>Task Wrapper: Build(flags, [KEY=VALUE])
Task Wrapper->>Task Executor: RunTask(options{Name: "build"}, [KEY=VALUE])
Task Executor->>Task Executor: Parse task name & CLI vars
Task Executor->>Task Executor: Execute Taskfile task with vars
Task Executor-->>Task Wrapper: Task result
Task Wrapper-->>CLI (wails3): Result
CLI (wails3)-->>User: Output
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~18 minutes Suggested labels
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Deploying wails with
|
| Latest commit: |
470a5e3
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://ca2917b0.wails.pages.dev |
| Branch Preview URL: | https://vk-deec-update-cli.wails.pages.dev |
|
Semgrep found 1 Risk: Affected versions of rollup are vulnerable to Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'). Manual Review Advice: A vulnerability from this advisory is reachable if you use Rollup to bundle JavaScript with Fix: Upgrade this library to at least version 3.29.5 at wails/v3/examples/dev/frontend/package-lock.json:569. Reference(s): GHSA-gcx4-mw62-g8wm, CVE-2024-47068 |
There was a problem hiding this comment.
Actionable comments posted: 5
🔭 Outside diff range comments (1)
docs/src/content/docs/guides/cli.mdx (1)
489-496: Reconciletool packageflags table with implementationThe existing table in docs/src/content/docs/guides/cli.mdx omits two flags and misaligns descriptions. Update it to match the
ToolPackagestruct:• File: docs/src/content/docs/guides/cli.mdx (under “#### Flags” for
tool package)
Replace the current table with:#### Flags | Flag | Description | Default | |-----------------|-----------------------------------------------------------|---------| | `-format` | Package format to generate (deb, rpm, archlinux, dmg) | `deb` | | `-name` | Name of the executable to package | `myapp` | | `-config` | Path to the package configuration file | | | `-out` | Path to the output directory | `.` | | `-background` | Path to an optional background image for the DMG | | | `-create-dmg` | Create a DMG file (macOS only) | `false` |Also remove the duplicate/conflicting flags table elsewhere in this guide.
🧹 Nitpick comments (6)
v3/cmd/wails3/main.go (2)
37-42: Forwarding args looks correct; add LongDescription to advertise CLI variablesImplementation mirrors
taskand correctly forwardsbuild.OtherArgs(). Add help text to make the feature discoverable viawails3 build -h.build := app.NewSubCommand("build", "Build the project") var buildFlags flags.Build build.AddFlags(&buildFlags) build.Action(func() error { return commands.Build(&buildFlags, build.OtherArgs()) }) +build.LongDescription("\nUsage: wails3 build [CLI variables...]\n\nThis command forwards CLI variables (e.g. KEY=VALUE) to the underlying Taskfile task.\nEquivalent to: wails3 task build\nExamples:\n wails3 build PLATFORM=linux CONFIG=production")
46-51: Same here: add LongDescription forpackageto advertise var forwardingLogic is good. Improve UX of
-hby documenting CLI variables here too.pkg := app.NewSubCommand("package", "Package application") var pkgFlags flags.Package pkg.AddFlags(&pkgFlags) pkg.Action(func() error { return commands.Package(&pkgFlags, pkg.OtherArgs()) }) +pkg.LongDescription("\nUsage: wails3 package [CLI variables...]\n\nThis command forwards CLI variables (e.g. KEY=VALUE) to the underlying Taskfile task.\nEquivalent to: wails3 task package\nExamples:\n wails3 package VERSION=2.0.0 OUTPUT=myapp.pkg")docs/src/content/docs/learn/build.mdx (1)
141-163: Add a short note about quoting values with spacesUsers often pass values with spaces (e.g., product names). Recommend quoting to avoid shell splitting.
### Passing Parameters to Tasks You can pass CLI variables to tasks using the `KEY=VALUE` format. These variables are forwarded through the alias commands: @@ wails3 package VERSION=2.0.0 OUTPUT=myapp.pkgIn your
Taskfile.yml, you can access these variables using Go template syntax:
+
+Tip: If a value contains spaces, quote it:
+
+bash +wails3 build PRODUCT_NAME="My App" CONFIG="production debug" +tasks: build: cmds: - echo "Building for {{.PLATFORM | default "darwin"}}" - go build -tags {{.CONFIG | default "debug"}} -o myapp</blockquote></details> <details> <summary>v3/internal/commands/task_wrapper.go (1)</summary><blockquote> `21-29`: **Global `os.Args` mutation has lasting side-effects** `wrapTask` rewrites `os.Args` and never restores it. For a long-running CLI that may call multiple sub-commands in-process (or unit tests executed after Build/Package), this leaks mutated state. Consider deferring a restore of the original slice or passing arguments directly to the Task executor instead. </blockquote></details> <details> <summary>v3/internal/commands/task_integration_test.go (1)</summary><blockquote> `15-19`: **CI gating is fragile** The tests only skip when both `CI=true` **and** `SKIP_INTEGRATION_TESTS=true`. Most CI environments will run the suite unexpectedly. Recommend skipping when _either_ variable is set or using a single well-known env flag. </blockquote></details> <details> <summary>v3/internal/commands/task.go (1)</summary><blockquote> `170-178`: **Small optimisation opportunity** `strings.Contains(v, "=")` followed by `strings.SplitN(v, "=", 2)` scans the string twice. Use `idx := strings.IndexByte(v,'=')` once to find the separator and slice, mirroring the helper used in tests. </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: .coderabbit.yaml** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 3f11d4e3fa2639cc7bfd5b676d44db3eb18b55b9 and a5253c7d7a134827178a99d33f1bbfeaf9552355. </details> <details> <summary>📒 Files selected for processing (10)</summary> * `docs/src/content/docs/guides/cli.mdx` (4 hunks) * `docs/src/content/docs/learn/build.mdx` (1 hunks) * `v3/UNRELEASED_CHANGELOG.md` (1 hunks) * `v3/cmd/wails3/main.go` (1 hunks) * `v3/go.mod` (2 hunks) * `v3/internal/commands/task.go` (1 hunks) * `v3/internal/commands/task_integration_test.go` (1 hunks) * `v3/internal/commands/task_test.go` (1 hunks) * `v3/internal/commands/task_wrapper.go` (1 hunks) * `v3/internal/commands/task_wrapper_test.go` (1 hunks) </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>🧠 Learnings (7)</summary> <details> <summary>📚 Learning: 2025-02-04T23:59:43.956Z</summary>Learnt from: fbbdev
PR: #4045
File: v3/internal/generator/render/info.go:28-68
Timestamp: 2025-02-04T23:59:43.956Z
Learning: In the Wails v3 project, internal functions are designed to panic on nil parameters as they represent contract violations, rather than adding defensive nil checks.**Applied to files:** - `v3/cmd/wails3/main.go` </details> <details> <summary>📚 Learning: 2025-04-29T23:54:07.488Z</summary>Learnt from: popaprozac
PR: #4256
File: v2/internal/frontend/desktop/linux/notifications.go:27-28
Timestamp: 2025-04-29T23:54:07.488Z
Learning: In Wails v2, unlike v3-alpha which has aServiceShutdownmethod for services, there is no standardized teardown pattern for frontend implementations. When implementing features that require cleanup (like goroutines or resources), add explicit cleanup methods (e.g.,CleanupNotifications()) that handle resource release, context cancellation, and connection closure.**Applied to files:** - `v3/cmd/wails3/main.go` </details> <details> <summary>📚 Learning: 2024-12-02T22:00:10.339Z</summary>Learnt from: stavros-k
PR: #3917
File: docs/astro.config.mjs:0-0
Timestamp: 2024-12-02T22:00:10.339Z
Learning: In the Wails documentation, all content under 'docs/src/content/docs' is accessible at the root path '/', so links in the sidebar configuration should not include the '/docs' prefix.**Applied to files:** - `docs/src/content/docs/guides/cli.mdx` </details> <details> <summary>📚 Learning: 2024-09-15T21:32:51.758Z</summary>Learnt from: leaanthony
PR: #3748
File: v3/internal/templates/_common/Taskfile.tmpl.yml:18-18
Timestamp: 2024-09-15T21:32:51.758Z
Learning: In Taskfile, variables are referenced using{{ "{{variable}}" }}without the dot notation to differentiate them from Go template variables.**Applied to files:** - `docs/src/content/docs/guides/cli.mdx` - `docs/src/content/docs/learn/build.mdx` - `v3/internal/commands/task_integration_test.go` - `v3/internal/commands/task.go` - `v3/internal/commands/task_test.go` </details> <details> <summary>📚 Learning: 2024-09-30T06:14:32.602Z</summary>Learnt from: leaanthony
PR: #3763
File: v3/internal/commands/appimage_testfiles/main.go:295-299
Timestamp: 2024-09-30T06:14:32.602Z
Learning: Inv3/internal/commands/appimage_testfiles/main.go,time.Sleepis used within a goroutine and does not block the UI thread.**Applied to files:** - `v3/internal/commands/task_wrapper_test.go` - `v3/internal/commands/task_integration_test.go` </details> <details> <summary>📚 Learning: 2025-01-15T22:40:58.594Z</summary>Learnt from: fbbdev
PR: #4001
File: v3/internal/generator/testcases/aliases/main.go:65-68
Timestamp: 2025-01-15T22:40:58.594Z
Learning: Files inv3/internal/generator/testcasesare test dummies used for testing purposes only. They are never compiled into the application and should not be subject to the same level of code review as production code.**Applied to files:** - `v3/internal/commands/task_wrapper_test.go` - `v3/internal/commands/task_integration_test.go` </details> <details> <summary>📚 Learning: 2024-09-15T11:08:01.900Z</summary>Learnt from: leaanthony
PR: #3748
File: v3/internal/templates/_common/Taskfile.tmpl.yml:18-18
Timestamp: 2024-09-15T11:08:01.900Z
Learning: In Taskfile, variables are referenced using{{ "{{variable}}" }}without the dot notation.**Applied to files:** - `docs/src/content/docs/learn/build.mdx` - `v3/internal/commands/task.go` - `v3/internal/commands/task_test.go` </details> </details> </details> <details> <summary>⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)</summary> * GitHub Check: Cloudflare Pages </details> <details> <summary>🔇 Additional comments (7)</summary><blockquote> <details> <summary>v3/go.mod (2)</summary> `54-54`: **LGTM: difflib is a transitive dep of testify** `github.com/pmezard/go-difflib v1.0.0` as indirect is expected. Nothing to change. --- `35-35`: **Testify usage confined to tests—no changes needed** Confirmed via code search that there are no imports of `github.com/stretchr/testify` in non-`*_test.go` files. Keeping the direct `testify v1.10.0` requirement in `v3/go.mod` is appropriate. </details> <details> <summary>v3/UNRELEASED_CHANGELOG.md (1)</summary> `21-21`: **Changelog entry reads well and matches user-facing behavior** Tense, scope, and references look good. </details> <details> <summary>docs/src/content/docs/guides/cli.mdx (3)</summary> `79-90`: **Nice: build usage now shows CLI variables and forwarding behavior** Clear examples and note about forwarding. Good alignment with code. --- `96-117`: **Package usage/forwarding docs look good** Examples and note align with the CLI changes. --- `120-188`: **Great new `task` section; comprehensive and consistent with feature** This improves discoverability and matches the implementation. </details> <details> <summary>v3/internal/commands/task_wrapper_test.go (1)</summary> `65-71`: **Possible nil dereference in assertions** If `wrapTaskInternal` returns early (e.g. future error path), `capturedOptions` remains `nil` and `capturedOptions.Name` panics. Add a `require.NotNil(t, capturedOptions)` before dereferencing. <details> <summary>⛔ Skipped due to learnings</summary>Learnt from: fbbdev
PR: #4045
File: v3/internal/generator/render/info.go:28-68
Timestamp: 2025-02-04T23:59:43.956Z
Learning: In the Wails v3 project, internal functions are designed to panic on nil parameters as they represent contract violations, rather than adding defensive nil checks.Learnt from: fbbdev
PR: #4001
File: v3/internal/generator/analyse_test.go:105-107
Timestamp: 2025-01-15T22:42:09.774Z
Learning: In the FindServices function of v3/internal/generator/analyse.go, services should never be nil when err is nil. This is a design contract and any violation should result in a panic rather than being handled silently.</details> </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
| taskfileContent := `version: '3' | ||
|
|
||
| tasks: | ||
| build: | ||
| cmds: | ||
| - echo "PLATFORM={{.PLATFORM | default "default-platform"}}" | ||
| - echo "CONFIG={{.CONFIG | default "default-config"}}" | ||
| silent: true | ||
|
|
||
| package: | ||
| cmds: | ||
| - echo "VERSION={{.VERSION | default "1.0.0"}}" | ||
| - echo "OUTPUT={{.OUTPUT | default "output.pkg"}}" | ||
| silent: true | ||
|
|
||
| test: | ||
| cmds: | ||
| - echo "ENV={{.ENV | default "test"}}" | ||
| - echo "FLAGS={{.FLAGS | default "none"}}" | ||
| silent: true | ||
| ` |
There was a problem hiding this comment.
YAML quoting will break the test Taskfile
Nested double quotes inside another double-quoted string produce invalid shell syntax:
- echo "PLATFORM={{.PLATFORM | default "default-platform"}}"Escape the inner quotes or switch to single quotes around the default value, e.g.:
- echo 'PLATFORM={{.PLATFORM | default "default-platform"}}'Repeat for every similar line to avoid Taskfile parsing / shell errors.
🤖 Prompt for AI Agents
In v3/internal/commands/task_integration_test.go between lines 27 and 47, the
YAML string contains nested double quotes which cause invalid shell syntax. To
fix this, replace the inner double quotes around default values with single
quotes or escape them properly. For example, change lines like echo
"PLATFORM={{.PLATFORM | default "default-platform"}}" to use single quotes
around the default value or escape the inner quotes to ensure valid YAML and
shell syntax. Apply this fix consistently to all similar lines in the
taskfileContent string.
| // Helper function to extract the task parsing logic for testing | ||
| func parseTaskCall(options *RunTaskOptions, otherArgs []string) *ast.Call { | ||
| var tasksAndVars []string | ||
|
|
||
| // Check if we have a task name specified in options | ||
| if options.Name != "" { | ||
| // If task name is provided via options, use it and treat otherArgs as CLI variables | ||
| tasksAndVars = append([]string{options.Name}, otherArgs...) | ||
| } else if len(otherArgs) > 0 { | ||
| // Use otherArgs directly if provided | ||
| tasksAndVars = otherArgs | ||
| } else { | ||
| // Fall back to parsing os.Args for backward compatibility | ||
| var index int | ||
| var arg string | ||
| for index, arg = range os.Args[2:] { | ||
| if len(arg) > 0 && arg[0] != '-' { | ||
| break | ||
| } | ||
| } | ||
|
|
||
| for _, taskAndVar := range os.Args[index+2:] { | ||
| if taskAndVar == "--" { | ||
| break | ||
| } | ||
| tasksAndVars = append(tasksAndVars, taskAndVar) | ||
| } | ||
| } | ||
|
|
||
| // Default task | ||
| if len(tasksAndVars) == 0 { | ||
| tasksAndVars = []string{"default"} | ||
| } | ||
|
|
||
| // Parse task name and CLI variables | ||
| taskName := tasksAndVars[0] | ||
| cliVars := tasksAndVars[1:] | ||
|
|
||
| // Create call with CLI variables | ||
| call := &ast.Call{ | ||
| Task: taskName, | ||
| Vars: &ast.Vars{}, | ||
| } | ||
|
|
||
| // Parse CLI variables (format: KEY=VALUE) | ||
| for _, v := range cliVars { | ||
| if idx := findEquals(v); idx != -1 { | ||
| key := v[:idx] | ||
| value := v[idx+1:] | ||
| call.Vars.Set(key, ast.Var{ | ||
| Value: value, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| return call | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Test duplicates production parsing logic
parseTaskCall re-implements the same logic that RunTask executes.
If the production code regresses, these tests may still pass because they share the same bug.
Prefer testing the real RunTask workflow (with a mocked executor) rather than copying its internals.
🤖 Prompt for AI Agents
In v3/internal/commands/task_test.go between lines 122 and 178, the
parseTaskCall function duplicates the task parsing logic from the production
RunTask function, risking tests passing despite regressions. To fix this, remove
the parseTaskCall helper and instead write tests that invoke the actual RunTask
function with a mocked executor to verify behavior, ensuring tests reflect real
production code execution and catch regressions.
| // Variables to enable mocking in tests | ||
| var ( | ||
| wrapTaskFunc = wrapTask | ||
| ) |
There was a problem hiding this comment.
Compilation fails – unused global wrapTaskFunc
This package-level variable is never referenced in the test file, so go test will error with “wrapTaskFunc declared but not used”.
Delete it or use it; otherwise the whole test suite won’t compile.
🤖 Prompt for AI Agents
In v3/internal/commands/task_wrapper_test.go around lines 131 to 134, the
package-level variable wrapTaskFunc is declared but never used, causing
compilation errors. To fix this, either remove the wrapTaskFunc variable
entirely if it is unnecessary, or update the test code to reference wrapTaskFunc
where mocking is intended. Ensure that all declared variables are used to avoid
compilation failures.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|
* feat: Update CLI to pass parameters through to Task commands - Modified build and package commands to accept otherArgs parameter - Updated task wrapper to forward CLI variables to Task - Enhanced task.go to properly parse and handle CLI variables (KEY=VALUE format) - Fixes issue where 'wails3 build' and 'wails3 package' commands weren't forwarding parameters Fixes wailsapp#4422 * Update changelog * Apply suggestion from @coderabbitai[bot] Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Fix cli.mdx --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>



Passes through variables to the in-built task commands:
wails3 buildandwails3 pacakgeSummary by CodeRabbit
New Features
wails3 buildandwails3 packagecommands, allowing for more flexible task configuration.Documentation
taskcommand.Bug Fixes
Tests