Allow linker to perform deadcode elimination for programs using kingpin#20
Draft
rosstimothy wants to merge 1 commit intomasterfrom
Draft
Allow linker to perform deadcode elimination for programs using kingpin#20rosstimothy wants to merge 1 commit intomasterfrom
rosstimothy wants to merge 1 commit intomasterfrom
Conversation
The usage rendering was performed with text/template in a way that resulted in the template package being reliant on reflect.MethodByName. As a result, Go's dead code elimination is prevented from running which has a cascading effect on any downstream consumers of kingpin. This changes the usage rendering of kingpin such that text/template is not used by default. The existing templates were converted into pure Go functions, and an extensive test suite was added to ensure equality with the legacy templates. Default applications now use the pure Go equivalent of kingpin.DefaultUsageTemplate. The existing UsageTemplate and UsageFuncs APIs remain intact to preserve compatibility. Any use of either API will result in text/template rendering usage and preventing deadcode elimination. To customize rendering without the use of text/template, a pure Go renderer may be specified via UsageRenderer. All of the existing legacy templates and shell completions have an exported and equivalent pure Go renderer exposed. Additionally, some of the internal rendering functions have been exported to make writing custom Go usage rendering easier for consumers of kingpin.
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.
The usage rendering was performed with text/template in a way that resulted in the template package being reliant on reflect.MethodByName. As a result, Go's dead code elimination is prevented from running which has a cascading effect on any downstream consumers of kingpin.
This changes the usage rendering of kingpin such that text/template is not used by default. The existing templates were converted into pure Go functions, and an extensive test suite was added to ensure equality with the legacy templates. Default applications now use the pure Go equivalent of kingpin.DefaultUsageTemplate. The existing UsageTemplate and UsageFuncs APIs remain intact to preserve compatibility. Any use of either API will result in text/template rendering usage and preventing deadcode elimination.
To customize rendering without the use of text/template, a pure Go renderer may be specified via UsageRenderer. All of the existing legacy templates and shell completions have an exported and equivalent pure Go renderer exposed. Additionally, some of the internal rendering functions have been exported to make writing custom Go usage rendering easier for consumers of kingpin.