Skip to content

Commit

Permalink
Merge pull request #138 from AlexanderYastrebov/remove-template
Browse files Browse the repository at this point in the history
Remove use of text/template
  • Loading branch information
tianon committed Mar 20, 2024
2 parents b73cc93 + 96e1ec4 commit a7a1ca6
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main // import "github.com/tianon/gosu"

import (
"bytes"
"fmt"
"log"
"os"
Expand All @@ -10,7 +9,6 @@ import (
"runtime"
"strings"
"syscall"
"text/template"
)

func init() {
Expand All @@ -24,24 +22,18 @@ func version() string {
}

func usage() string {
t := template.Must(template.New("usage").Parse(`
t := `
Usage: {{ .Self }} user-spec command [args]
eg: {{ .Self }} tianon bash
{{ .Self }} nobody:root bash -c 'whoami && id'
{{ .Self }} 1000:1 id
{{ .Self }} version: {{ .Version }}
{{ .Self }} license: Apache-2.0 (full text at https://github.com/tianon/gosu)
`))
var b bytes.Buffer
template.Must(t, t.Execute(&b, struct {
Self string
Version string
}{
Self: filepath.Base(os.Args[0]),
Version: version(),
}))
return strings.TrimSpace(b.String()) + "\n"
`
t = strings.ReplaceAll(t, "{{ .Self }}", filepath.Base(os.Args[0]))
t = strings.ReplaceAll(t, "{{ .Version }}", version())
return t[1:]
}

func main() {
Expand Down

0 comments on commit a7a1ca6

Please sign in to comment.