Conversation
a623026 to
5353c83
Compare
5353c83 to
9c76e37
Compare
9c76e37 to
c8355ee
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates muxt to support specifying --use-templates-variable multiple times so generation, checking, and template-reference inspection can operate across multiple independent *template.Template sets (namespaces), while still detecting route-pattern collisions at generation time.
Changes:
- Make
--use-templates-variablevariadic across CLI commands, with backward-compatible handling of the deprecated--templates-variableflag. - Tag each parsed route definition with its originating templates variable and generate handlers that call
ExecuteTemplateon the correct variable. - Add/extend tests + reference txtar fixtures and update CLI/docs to describe multi-variable usage and duplicate route detection.
Reviewed changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/muxt/definition.go | Add templates-variable context to Definitions, normalize patterns, and introduce CheckForDuplicatePatterns. |
| internal/generate/routes.go | Load/merge definitions from multiple template variables; generate handlers using def.TemplatesVariable(). |
| internal/cli/commands.go | Change --use-templates-variable to slice; add validation/compat helpers; iterate per templates-variable for analysis-style commands. |
| internal/analysis/check.go | Run template checking per templates-variable. |
| internal/analysis/routes.go | Make routes output support multiple template variables. |
| internal/asteval/package.go | Load packages with NeedImports (supports cross-package scenarios). |
| internal/muxt/definition_test.go | Add tests for duplicate pattern detection and normalization behavior. |
| internal/cli/commands_test.go | Add tests for templates-variable slice normalization and duplicate detection. |
| docs/reference/templates-variable.md | Document multiple template variables and behavior implications. |
| docs/reference/cli.md | Update CLI reference to reflect --use-templates-variable as string[]. |
| cmd/muxt/testdata/* | Add/update script fixtures covering multi-variable generation/checking and error cases. |
| .gitignore | Ignore .claude/plans. |
The --use-templates-variable flag now accepts multiple values, letting each *template.Template variable form an independent namespace with its own functions, options, and embed.FS. This unblocks scaling apps that need separate template sets (admin vs public, or reusable components mounted into a host app) without forcing globally unique template names. Each generated handler dispatches ExecuteTemplate on the variable that owns its template. Cross-variable duplicate route patterns are detected at generate time. The deprecated --templates-variable flag still works alone but cannot be combined with the new flag. resolves: #67
c8355ee to
2692adb
Compare
Member
Author
|
Addressed all five Copilot comments in the latest force-push (2692adb):
Also added a JSON-format assertion to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
resolves: #67
Why
*template.Templatekeeps every{{define}}name in a single global namespace. As an app grows or you try to share templates across projects, that becomes a bottleneck:{{define "header"}}without one silently overwriting the other.Funcsmap, one set ofOptions, and oneembed.FS.The workaround today is to set every output flag and run
muxt generateper package, but that leavesTemplateRoutePathsincomplete (each generated file only knows its own routes) and pushes duplicate-pattern detection to runtime inhttp.ServeMux.Approach
--use-templates-variablebecomes variadic. Each variable is the root of an independent namespace and contributes routes to a single combinedTemplateRoutesfunction. Cross-variable duplicate route patterns are caught at generate time.TemplateRoutePathscovers everything because it sees all routes in one pass.The user-facing rationale lives in
docs/reference/templates-variable.md(Multiple Template Variables section).Test plan
go test ./...,go vet ./...,staticcheck ./...,gofumpt -d .— all cleanembed.FS, cross-variable duplicate-pattern detection, per-variable unused-template detection, missing variable, and the deprecated/new flag mutexfixTemplateVariables/findDuplicateVariablesandCheckForDuplicatePatterns(method/host/path normalization)