cmd/internal/doc: merge with cmd/go/internal/doc

Now that cmd/doc has been removed, cmd/go/internal/doc is the only user
of the cmd/internal/doc code. Merge cmd/internal/doc into
cmd/go/internal/doc.

For #74667

Change-Id: I16bbe7b1f418b54ee411c8d6e6609c0973e40b3e
Reviewed-on: https://go-review.googlesource.com/c/go/+/689836
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Michael Matloob 2025-07-23 11:25:14 -04:00 committed by Michael Matloob
parent da8b50c830
commit bd446662dd
13 changed files with 22 additions and 19 deletions

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !cmd_go_bootstrap
package doc
import (

View file

@ -8,9 +8,12 @@
package doc
import (
"cmd/go/internal/base"
"cmd/internal/doc"
"context"
"flag"
"log"
"os"
"cmd/go/internal/base"
)
var CmdDoc = &base.Command{
@ -136,5 +139,12 @@ Flags:
}
func runDoc(ctx context.Context, cmd *base.Command, args []string) {
doc.Main(args)
log.SetFlags(0)
log.SetPrefix("doc: ")
dirsInit()
var flagSet flag.FlagSet
err := do(os.Stdout, &flagSet, args)
if err != nil {
log.Fatal(err)
}
}

View file

@ -29,7 +29,7 @@ func TestMain(m *testing.M) {
buildCtx.GOROOT = testenv.GOROOT(nil)
build.Default.GOROOT = testenv.GOROOT(nil)
// Add $GOROOT/src/cmd/doc/testdata explicitly so we can access its contents in the test.
// Add $GOROOT/src/cmd/go/internal/doc/testdata explicitly so we can access its contents in the test.
// Normally testdata directories are ignored, but sending it to dirs.scan directly is
// a hack that works around the check.
testdataDir, err := filepath.Abs("testdata")
@ -90,7 +90,7 @@ type test struct {
no []string // Regular expressions that should not match.
}
const p = "cmd/internal/doc/testdata"
const p = "cmd/go/internal/doc/testdata"
var tests = []test{
// Sanity check.
@ -105,7 +105,7 @@ var tests = []test{
{
"package clause",
[]string{p},
[]string{`package pkg.*cmd/internal/doc/testdata`},
[]string{`package pkg.*cmd/go/internal/doc/testdata`},
nil,
},

View file

@ -2,7 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package doc provides the implementation of the "go doc" subcommand and cmd/doc.
//go:build !cmd_go_bootstrap
package doc
import (
@ -53,18 +54,6 @@ func usage(flagSet *flag.FlagSet) {
os.Exit(2)
}
// Main is the entry point, invoked both by go doc and cmd/doc.
func Main(args []string) {
log.SetFlags(0)
log.SetPrefix("doc: ")
dirsInit()
var flagSet flag.FlagSet
err := do(os.Stdout, &flagSet, args)
if err != nil {
log.Fatal(err)
}
}
// do is the workhorse, broken out of main to make testing easier.
func do(writer io.Writer, flagSet *flag.FlagSet, args []string) (err error) {
flagSet.Usage = func() { usage(flagSet) }

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !cmd_go_bootstrap
package doc
import (