It's common to use the go list command in shell scripts, but
currently it's awkward to print a string slice from the Package
type in a way that's easily parseable by the shell. For example:
go list -f '{{range .Deps}}{{.}}
{{end}}'
(and even that prints an unwanted new line at the end|).
To make this easier, this CL adds a "join" function to the
format template.
go list -f '{{join .Deps "\n"}}'
R=rsc, dsymonds, minux.ma, remyoudompheng, r
CC=golang-dev
https://golang.org/cl/
6680044
"encoding/json"
"io"
"os"
+ "strings"
"text/template"
)
code.google.com/p/goauth2/oauth
code.google.com/p/sqlite
-The -f flag specifies an alternate format for the list,
-using the syntax of package template. The default output
-is equivalent to -f '{{.ImportPath}}'. The struct
-being passed to the template is:
+The -f flag specifies an alternate format for the list, using the
+syntax of package template. The default output is equivalent to -f
+'{{.ImportPath}}'. One extra template function is available, "join",
+which calls strings.Join. The struct being passed to the template is:
type Package struct {
Dir string // directory containing package sources
out.Write(nl)
}
} else {
- tmpl, err := template.New("main").Parse(*listFmt)
+ tmpl, err := template.New("main").Funcs(template.FuncMap{"join": strings.Join}).Parse(*listFmt)
if err != nil {
fatalf("%s", err)
}