mirror of
https://github.com/golang/go
synced 2024-11-17 12:54:47 -07:00
cmd/go: remove invalid space in import comment docs
Generate package comment in alldocs.go using line comments rather than general comments. This scales better, general comments cannot contain the "*/" character sequence. Line comments do not have any restrictions on the comment text that can be contained. Remove the dependency on sed, which is not cross-platform, not go-gettable external command. Remove trailing whitespace from usage string in test.go. It's unnecessary. Fixes #16030. Change-Id: I3c0bc9955e7c7603c3d1fb4878218b0719d02e04 Reviewed-on: https://go-review.googlesource.com/23968 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
c83e6f50d9
commit
2ba3d5fc96
File diff suppressed because it is too large
Load Diff
@ -214,15 +214,7 @@ var helpTemplate = `{{if .Runnable}}usage: go {{.UsageLine}}
|
||||
{{end}}{{.Long | trim}}
|
||||
`
|
||||
|
||||
var documentationTemplate = `// Copyright 2011 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// DO NOT EDIT THIS FILE. GENERATED BY mkalldocs.sh.
|
||||
// Edit the documentation in other files and rerun mkalldocs.sh to generate this one.
|
||||
|
||||
/*
|
||||
{{range .}}{{if .Short}}{{.Short | capitalize}}
|
||||
var documentationTemplate = `{{range .}}{{if .Short}}{{.Short | capitalize}}
|
||||
|
||||
{{end}}{{if .Runnable}}Usage:
|
||||
|
||||
@ -231,9 +223,39 @@ var documentationTemplate = `// Copyright 2011 The Go Authors. All rights reserv
|
||||
{{end}}{{.Long | trim}}
|
||||
|
||||
|
||||
{{end}}*/
|
||||
package main
|
||||
`
|
||||
{{end}}`
|
||||
|
||||
// commentWriter writes a Go comment to the underlying io.Writer,
|
||||
// using line comment form (//).
|
||||
type commentWriter struct {
|
||||
W io.Writer
|
||||
wroteSlashes bool // Wrote "//" at the beginning of the current line.
|
||||
}
|
||||
|
||||
func (c *commentWriter) Write(p []byte) (int, error) {
|
||||
var n int
|
||||
for i, b := range p {
|
||||
if !c.wroteSlashes {
|
||||
s := "//"
|
||||
if b != '\n' {
|
||||
s = "// "
|
||||
}
|
||||
if _, err := io.WriteString(c.W, s); err != nil {
|
||||
return n, err
|
||||
}
|
||||
c.wroteSlashes = true
|
||||
}
|
||||
n0, err := c.W.Write(p[i : i+1])
|
||||
n += n0
|
||||
if err != nil {
|
||||
return n, err
|
||||
}
|
||||
if b == '\n' {
|
||||
c.wroteSlashes = false
|
||||
}
|
||||
}
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
// An errWriter wraps a writer, recording whether a write error occurred.
|
||||
type errWriter struct {
|
||||
@ -310,10 +332,18 @@ func help(args []string) {
|
||||
|
||||
// 'go help documentation' generates doc.go.
|
||||
if arg == "documentation" {
|
||||
fmt.Println("// Copyright 2011 The Go Authors. All rights reserved.")
|
||||
fmt.Println("// Use of this source code is governed by a BSD-style")
|
||||
fmt.Println("// license that can be found in the LICENSE file.")
|
||||
fmt.Println()
|
||||
fmt.Println("// DO NOT EDIT THIS FILE. GENERATED BY mkalldocs.sh.")
|
||||
fmt.Println("// Edit the documentation in other files and rerun mkalldocs.sh to generate this one.")
|
||||
fmt.Println()
|
||||
buf := new(bytes.Buffer)
|
||||
printUsage(buf)
|
||||
usage := &Command{Long: buf.String()}
|
||||
tmpl(os.Stdout, documentationTemplate, append([]*Command{usage}, commands...))
|
||||
tmpl(&commentWriter{W: os.Stdout}, documentationTemplate, append([]*Command{usage}, commands...))
|
||||
fmt.Println("package main")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
set -e
|
||||
|
||||
go build -o go.latest
|
||||
./go.latest help documentation | sed 's; \*/; * /;' >alldocs.go
|
||||
./go.latest help documentation >alldocs.go
|
||||
gofmt -w alldocs.go
|
||||
rm go.latest
|
||||
|
||||
|
@ -129,7 +129,7 @@ control the execution of any test:
|
||||
const testFlag2 = `
|
||||
-bench regexp
|
||||
Run (sub)benchmarks matching a regular expression.
|
||||
The given regular expression is split into smaller ones by
|
||||
The given regular expression is split into smaller ones by
|
||||
top-level '/', where each must match the corresponding part of a
|
||||
benchmark's identifier.
|
||||
By default, no benchmarks run. To run all benchmarks,
|
||||
@ -221,7 +221,7 @@ const testFlag2 = `
|
||||
-run regexp
|
||||
Run only those tests and examples matching the regular expression.
|
||||
For tests the regular expression is split into smaller ones by
|
||||
top-level '/', where each must match the corresponding part of a
|
||||
top-level '/', where each must match the corresponding part of a
|
||||
test's identifier.
|
||||
|
||||
-short
|
||||
@ -263,7 +263,7 @@ execution, not to the test itself.)
|
||||
The test flags that generate profiles (other than for coverage) also
|
||||
leave the test binary in pkg.test for use when analyzing the profiles.
|
||||
|
||||
When 'go test' runs a test binary, it does so from within the
|
||||
When 'go test' runs a test binary, it does so from within the
|
||||
corresponding package's source code directory. Depending on the test,
|
||||
it may be necessary to do the same when invoking a generated test
|
||||
binary directly.
|
||||
|
Loading…
Reference in New Issue
Block a user