Repository navigation
Conversation
This was referenced Sep 22, 2026
Move DefaultPrintHelpCustom and the fish completion template rendering to help_template.go, so that all uses of text/template are in one file. No functional change; this is a preparation for the next commit. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Using text/template makes the Go linker disable dead code elimination of exported methods for the whole program, since templates can call arbitrary methods by name (see golang/go#72895). For large programs, this results in a noticeably bigger binary. Add urfave_cli_no_template build tag, which renders the default help and fish completion without using text/template, producing the same output. Custom templates are not supported in this mode. The rendering code is generated from the default templates by internal/genhelp (run via go generate), which parses the templates using text/template/parse and compiles them into Go code, resolving fields and methods statically with the help of go/types. Only the subset of the template language used by the default templates is supported; anything else is a generation error. With this tag, examples/example-cli binary is 3.3 MB instead of 5.1 MB, and runc binary is 10.5 MB instead of 12.4 MB. Run tests with this tag in CI, skipping those that use custom templates, and add tests to ensure text/template is not linked in with this tag, and that the generated code is up to date. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Add a test which renders various help pages and fish completion for a few commands exercising most of the template features, and compares the result with a golden file. Since CI runs tests both with and without urfave_cli_no_template tag, this ensures both implementations produce the exact same output. To regenerate the golden file, run the test with UPDATE_GOLDEN=1. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
In check-binary-size, also show how much the package contributes to the binary size when built with urfave_cli_no_template tag. This is for informational purposes only; the limits are checked for the default build. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin
force-pushed
the
no-template-codegen
branch
from
September 24, 2026 21:24
de71b4d to
7e61552
Compare
Member
|
Thanks! I reviewed both approaches together in #2441 (review) |
Contributor
Author
|
Closing in favor of #2441, as discussed in #2441 (review). |
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.
This is an alternative to #2441, which see for the motivation. The difference is how the template-less help rendering code is written:
internal/genhelp(run viago generate). It parses the templates usingtext/template/parseand compiles them into Go code, resolving fields and methods statically viago/types(stdlib only, no new dependencies). Anything outside of the template language subset used by the default templates (pipelines, unknown functions or fields etc.) is a generation error.Everything else (build tag, tests, CI, docs) is the same.
Pros and cons
go generateTestGeneratedHelpUpToDatein anygo testrunIn both cases, a build tag is required, since custom templates can't be rendered without
text/templateat runtime.I'm fine with either approach.
With this tag,
examples/example-cliis 3.3 MB instead of 5.1 MB, and runc is 10.5 MB instead of 12.4 MB (all 19 help pages of runc are byte-for-byte identical).Addresses #2277.