Skip to content

Allow linker to perform deadcode elimination for programs using kingpin#20

Draft
rosstimothy wants to merge 1 commit intomasterfrom
tross/dead_code
Draft

Allow linker to perform deadcode elimination for programs using kingpin#20
rosstimothy wants to merge 1 commit intomasterfrom
tross/dead_code

Conversation

@rosstimothy
Copy link
Copy Markdown

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant