Skip to content

Commit 60a80d2

Browse files
committed
Remove text/template from help generation
See the comment for details. Discovered via the CHANGELOG for Cobra v1.9.0, where a similar change was made (with far greater potential impact, given Cobra's level of usage throughout the community). Note that golang.org/x/net/trace, reachable via the Firestore client library, still links in the offending text/template methods. Why is the Firestore client even being built for Lambda? I'm only importing the dynamodb store package specifically. Maybe there's another dependent that `go mod why` missed?
1 parent 5fb09f2 commit 60a80d2

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

internal/randomizer/help.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
package randomizer
22

3-
import (
4-
"strings"
5-
"text/template"
6-
)
3+
import "strings"
74

85
func (a App) showHelp(request request) (Result, error) {
9-
var b strings.Builder
10-
helpMessageTemplate.Execute(&b, struct{ Name string }{a.name})
116
return Result{
127
resultType: ShowedHelp,
13-
message: b.String(),
8+
message: strings.ReplaceAll(helpMessageTemplate, "{{.Name}}", a.name),
149
}, nil
1510
}
1611

17-
var helpMessageTemplate = template.Must(template.New("").Parse(
18-
`{{.Name}} randomizes the order of options in a list.
12+
// helpMessageTemplate is written with text/template syntax for familiarity.
13+
// However, text/template uses reflection in a way that disables dead code
14+
// elimination for the _entire_ program, so we instead use plan string
15+
// replacement to substitute our one value.
16+
const helpMessageTemplate = `{{.Name}} randomizes the order of options in a list.
1917
2018
*Example:* {{.Name}} one two three
2119
> I randomized and got: *two*, *three*, *one*.
@@ -26,4 +24,4 @@ If you use a set of options a lot, try saving them as a *group* in the current c
2624
*Use a group:* {{.Name}} snacks
2725
*List your current channel's groups:* {{.Name}} /list
2826
*Show the options in a group:* {{.Name}} /show snacks
29-
*Delete a group:* {{.Name}} /delete snacks`))
27+
*Delete a group:* {{.Name}} /delete snacks`

0 commit comments

Comments
 (0)