Commit 707cadd7 authored by Russ Cox's avatar Russ Cox

cmd/go: split out cmd/go/internal/clean,doc,fix,generate,list,run,tool,version,vet

This is one CL in a long sequence of changes to break up the
go command from one package into a plausible group of packages.

This sequence is concerned only with moving code, not changing
or cleaning up code. There will still be more cleanup after this sequence.

The entire sequence will be submitted together: it is not a goal
for the tree to build at every step.

For #18653.

Change-Id: Ib22fc435827d4a05a77a5200ac437ce00e2a4da3
Reviewed-on: https://go-review.googlesource.com/36204Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
parent 76db88ab
This diff is collapsed.
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
package clean
import (
"fmt"
......@@ -17,7 +17,7 @@ import (
"cmd/go/internal/work"
)
var cmdClean = &base.Command{
var CmdClean = &base.Command{
UsageLine: "clean [-i] [-r] [-n] [-x] [build flags] [packages]",
Short: "remove object files",
Long: `
......@@ -68,15 +68,15 @@ var cleanR bool // clean -r flag
func init() {
// break init cycle
cmdClean.Run = runClean
CmdClean.Run = runClean
cmdClean.Flag.BoolVar(&cleanI, "i", false, "")
cmdClean.Flag.BoolVar(&cleanR, "r", false, "")
CmdClean.Flag.BoolVar(&cleanI, "i", false, "")
CmdClean.Flag.BoolVar(&cleanR, "r", false, "")
// -n and -x are important enough to be
// mentioned explicitly in the docs but they
// are part of the build flags.
work.AddBuildFlags(cmdClean)
work.AddBuildFlags(CmdClean)
}
func runClean(cmd *base.Command, args []string) {
......
......@@ -2,16 +2,14 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:generate ./mkalldocs.sh
package main
package doc
import (
"cmd/go/internal/base"
"cmd/go/internal/cfg"
)
var cmdDoc = &base.Command{
var CmdDoc = &base.Command{
Run: runDoc,
UsageLine: "doc [-u] [-c] [package|[package.]symbol[.method]]",
CustomFlags: true,
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
package fix
import (
"cmd/go/internal/base"
......@@ -11,7 +11,7 @@ import (
"cmd/go/internal/str"
)
var cmdFix = &base.Command{
var CmdFix = &base.Command{
Run: runFix,
UsageLine: "fix [packages]",
Short: "run go tool fix on packages",
......
......@@ -2,15 +2,11 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
package generate
import (
"bufio"
"bytes"
"cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/load"
"cmd/go/internal/work"
"fmt"
"io"
"log"
......@@ -20,9 +16,14 @@ import (
"regexp"
"strconv"
"strings"
"cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/load"
"cmd/go/internal/work"
)
var cmdGenerate = &base.Command{
var CmdGenerate = &base.Command{
Run: runGenerate,
UsageLine: "generate [-run regexp] [-n] [-v] [-x] [build flags] [file.go... | packages]",
Short: "generate Go files by processing source",
......@@ -135,8 +136,8 @@ var (
)
func init() {
work.AddBuildFlags(cmdGenerate)
cmdGenerate.Flag.StringVar(&generateRunFlag, "run", "", "")
work.AddBuildFlags(CmdGenerate)
CmdGenerate.Flag.StringVar(&generateRunFlag, "run", "", "")
}
func runGenerate(cmd *base.Command, args []string) {
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
package generate
import (
"reflect"
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
package get
import (
"cmd/go/internal/load"
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
package get
import "testing"
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
package get
import (
"errors"
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
package list
import (
"go/build"
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
package list
import (
"bufio"
......@@ -17,7 +17,7 @@ import (
"text/template"
)
var cmdList = &base.Command{
var CmdList = &base.Command{
UsageLine: "list [-e] [-f format] [-json] [build flags] [packages]",
Short: "list packages",
Long: `
......@@ -140,13 +140,13 @@ For more about specifying packages, see 'go help packages'.
}
func init() {
cmdList.Run = runList // break init cycle
work.AddBuildFlags(cmdList)
CmdList.Run = runList // break init cycle
work.AddBuildFlags(CmdList)
}
var listE = cmdList.Flag.Bool("e", false, "")
var listFmt = cmdList.Flag.String("f", "{{.ImportPath}}", "")
var listJson = cmdList.Flag.Bool("json", false, "")
var listE = CmdList.Flag.Bool("e", false, "")
var listFmt = CmdList.Flag.String("f", "{{.ImportPath}}", "")
var listJson = CmdList.Flag.Bool("json", false, "")
var nl = []byte{'\n'}
func runList(cmd *base.Command, args []string) {
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
package run
import (
"fmt"
......@@ -16,7 +16,7 @@ import (
"cmd/go/internal/work"
)
var cmdRun = &base.Command{
var CmdRun = &base.Command{
UsageLine: "run [build flags] [-exec xprog] gofiles... [arguments...]",
Short: "compile and run Go program",
Long: `
......@@ -40,10 +40,10 @@ See also: go build.
}
func init() {
cmdRun.Run = runRun // break init loop
CmdRun.Run = runRun // break init loop
work.AddBuildFlags(cmdRun)
cmdRun.Flag.Var((*base.StringsFlag)(&work.ExecCmd), "exec", "")
work.AddBuildFlags(CmdRun)
CmdRun.Flag.Var((*base.StringsFlag)(&work.ExecCmd), "exec", "")
}
func printStderr(args ...interface{}) (int, error) {
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
package tool
import (
"fmt"
......@@ -15,7 +15,7 @@ import (
"cmd/go/internal/cfg"
)
var cmdTool = &base.Command{
var CmdTool = &base.Command{
Run: runTool,
UsageLine: "tool [-n] command [args...]",
Short: "run specified go tool",
......@@ -33,7 +33,7 @@ For more about each tool command, see 'go tool command -h'.
var toolN bool
func init() {
cmdTool.Flag.BoolVar(&toolN, "n", false, "")
CmdTool.Flag.BoolVar(&toolN, "n", false, "")
}
func runTool(cmd *base.Command, args []string) {
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
package version
import (
"cmd/go/internal/base"
......@@ -10,7 +10,7 @@ import (
"runtime"
)
var cmdVersion = &base.Command{
var CmdVersion = &base.Command{
Run: runVersion,
UsageLine: "version",
Short: "print Go version",
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
package vet
import (
"path/filepath"
......@@ -15,10 +15,10 @@ import (
)
func init() {
work.AddBuildFlags(cmdVet)
work.AddBuildFlags(CmdVet)
}
var cmdVet = &base.Command{
var CmdVet = &base.Command{
Run: runVet,
UsageLine: "vet [-n] [-x] [build flags] [packages]",
Short: "run go tool vet on packages",
......
......@@ -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:generate ./mkalldocs.sh
package main
import (
......@@ -16,32 +18,41 @@ import (
"cmd/go/internal/base"
"cmd/go/internal/bug"
"cmd/go/internal/cfg"
"cmd/go/internal/clean"
"cmd/go/internal/doc"
"cmd/go/internal/env"
"cmd/go/internal/fix"
fmtcmd "cmd/go/internal/fmt"
"cmd/go/internal/generate"
"cmd/go/internal/get"
"cmd/go/internal/help"
"cmd/go/internal/list"
"cmd/go/internal/run"
"cmd/go/internal/test"
"cmd/go/internal/tool"
"cmd/go/internal/version"
"cmd/go/internal/vet"
"cmd/go/internal/work"
)
func init() {
base.Commands = []*base.Command{
work.CmdBuild,
cmdClean,
cmdDoc,
clean.CmdClean,
doc.CmdDoc,
env.CmdEnv,
bug.CmdBug,
cmdFix,
fix.CmdFix,
fmtcmd.CmdFmt,
cmdGenerate,
generate.CmdGenerate,
get.CmdGet,
work.CmdInstall,
cmdList,
cmdRun,
list.CmdList,
run.CmdRun,
test.CmdTest,
cmdTool,
cmdVersion,
cmdVet,
tool.CmdTool,
version.CmdVersion,
vet.CmdVet,
help.HelpC,
help.HelpBuildmode,
......@@ -130,8 +141,6 @@ func main() {
base.Exit()
}
var usage func()
func init() {
base.Usage = mainUsage
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment