It is possible to import pimp as a standalone Go library. The 3 examples below respectively show you how to print the git branches of a repository by:
package main
import (
"os"
"github.com/aymericbeaumet/pimp"
)
func main() {
_ = pimp.RenderTemplate(os.Stdout, `Git branches in {{pwd}}:
{{- range GitBranches}}
- {{.}}
{{- end}}
`)
}
package main
import (
"os"
"github.com/aymericbeaumet/pimp"
)
func main() {
_ = pimp.ExecuteScript(os.Stdout, `
printf "Git branches in %s:\n" pwd
range GitBranches
printf "- %s\n" .
end
`)
}
3. Use the pimp template functions with `text/template`
package main
import (
"os"
"text/template"
"github.com/aymericbeaumet/pimp"
)
func main() {
t, _ := template.New("git_branches").
Funcs(pimp.FuncMap()).
Parse(`Git branches in {{pwd}}:
{{- range GitBranches}}
- {{.}}
{{- end}}
`)
_ = t.Execute(os.Stdout, nil)
}