cmd/go: add join template function.
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"}}'
https://codereview.appspot.com/6680044/diff/5001/src/cmd/go/list.go File src/cmd/go/list.go (right): https://codereview.appspot.com/6680044/diff/5001/src/cmd/go/list.go#newcode130 src/cmd/go/list.go:130: if out.Count() > 0 { i still prefer to ...
12 years, 10 months ago
(2012-10-13 12:27:00 UTC)
#3
I also prefer join. Especially if I can write {{ .Deps | join ", " ...
12 years, 10 months ago
(2012-10-13 12:34:31 UTC)
#4
I also prefer join. Especially if I can write {{ .Deps | join ", " }}
2012/10/13, David Symonds <dsymonds@golang.org>:
> A join function would be better.
>
On Sat, Oct 13, 2012 at 8:34 PM, Rémy Oudompheng <remyoudompheng@gmail.com>wrote: > I also prefer ...
12 years, 10 months ago
(2012-10-13 12:38:48 UTC)
#5
On Sat, Oct 13, 2012 at 8:34 PM, Rémy Oudompheng
<remyoudompheng@gmail.com>wrote:
> I also prefer join. Especially if I can write {{ .Deps | join ", " }}
>
+1. join without hardcoding join character to \n is more useful.
I like the idea. Not sure it makes sense to swap the arguments. Now you ...
12 years, 10 months ago
(2012-10-16 17:36:14 UTC)
#7
I like the idea. Not sure it makes sense to swap the arguments. Now you can do
{{join .Deps ","}}
and even
{{join (complex|pipeline) ","}
I understand the rationale for putting it first, but it makes it different from
strings.Join, which I think will confuse Go programmers.
LGTM http://codereview.appspot.com/6680044/diff/20002/src/cmd/go/list.go File src/cmd/go/list.go (right): http://codereview.appspot.com/6680044/diff/20002/src/cmd/go/list.go#newcode31 src/cmd/go/list.go:31: which takes a slice of strings and a ...
12 years, 10 months ago
(2012-10-17 22:41:29 UTC)
#9
http://codereview.appspot.com/6680044/diff/20002/src/cmd/go/list.go File src/cmd/go/list.go (right): http://codereview.appspot.com/6680044/diff/20002/src/cmd/go/list.go#newcode31 src/cmd/go/list.go:31: which takes a slice of strings and a separator ...
12 years, 10 months ago
(2012-10-18 10:01:51 UTC)
#10
http://codereview.appspot.com/6680044/diff/20002/src/cmd/go/list.go
File src/cmd/go/list.go (right):
http://codereview.appspot.com/6680044/diff/20002/src/cmd/go/list.go#newcode31
src/cmd/go/list.go:31: which takes a slice of strings and a separator string and
returns
On 2012/10/17 22:41:29, dsymonds wrote:
> maybe it'd be simpler to reference strings.Join here, and then the user has a
> place to go to read about edge cases.
I considered this, but there really aren't any edge cases, and in general I
think it's nicer if docs for a command don't require looking in the package docs
too.
However, maybe:
// One extra template function is available, "join"
// which calls strings.Join.
is less awkward, and everyone should know about strings.Join already, right?
I'll go with that unless you or others have a better suggestion.
Yes, it is ad hoc. I'd really like to be able to conveniently use go ...
12 years, 10 months ago
(2012-10-18 12:05:34 UTC)
#12
Yes, it is ad hoc. I'd really like to be able to conveniently use go list
in shell scripts though. If you wanted to suggest adding
something that granted similar convenience to all templates,
I'd be very happy.
On 18 October 2012 11:55, Rob Pike <r@golang.org> wrote:
> This all feels too ad hoc to me.
>
> -rob
After cogitation and discussion I'm OK with this. http://codereview.appspot.com/6680044/diff/20002/src/cmd/go/list.go File src/cmd/go/list.go (right): http://codereview.appspot.com/6680044/diff/20002/src/cmd/go/list.go#newcode31 src/cmd/go/list.go:31: which ...
12 years, 10 months ago
(2012-10-19 21:24:18 UTC)
#13
*** Submitted as http://code.google.com/p/go/source/detail?r=117f773ed6b0 *** cmd/go: add join template function. It's common to use the ...
12 years, 9 months ago
(2012-10-22 07:59:07 UTC)
#14
*** Submitted as http://code.google.com/p/go/source/detail?r=117f773ed6b0 ***
cmd/go: add join template function.
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
http://codereview.appspot.com/6680044
Issue 6680044: code review 6680044: cmd/go: add join template function.
(Closed)
Created 12 years, 10 months ago by rog
Modified 12 years, 9 months ago
Reviewers:
Base URL:
Comments: 5