package base
import (
+ "context"
"flag"
"fmt"
"log"
type Command struct {
// Run runs the command.
// The args are the arguments after the command name.
- Run func(cmd *Command, args []string)
+ Run func(ctx context.Context, cmd *Command, args []string)
// UsageLine is the one-line usage message.
// The words between "go" and the first flag or argument in the line are taken to be the command name.
import (
"bytes"
+ "context"
"fmt"
"io"
"io/ioutil"
CmdBug.Flag.BoolVar(&cfg.BuildV, "v", false, "")
}
-func runBug(cmd *base.Command, args []string) {
+func runBug(ctx context.Context, cmd *base.Command, args []string) {
if len(args) > 0 {
base.Fatalf("go bug: bug takes no arguments")
}
package clean
import (
+ "context"
"fmt"
"io/ioutil"
"os"
work.AddBuildFlags(CmdClean, work.DefaultBuildFlags)
}
-func runClean(cmd *base.Command, args []string) {
+func runClean(ctx context.Context, cmd *base.Command, args []string) {
// golang.org/issue/29925: only load packages before cleaning if
// either the flags and arguments explicitly imply a package,
// or no other target (such as a cache) was requested to be cleaned.
import (
"cmd/go/internal/base"
"cmd/go/internal/cfg"
+ "context"
)
var CmdDoc = &base.Command{
`,
}
-func runDoc(cmd *base.Command, args []string) {
+func runDoc(ctx context.Context, cmd *base.Command, args []string) {
base.Run(cfg.BuildToolexec, base.Tool("doc"), args)
}
package envcmd
import (
+ "context"
"encoding/json"
"fmt"
"go/build"
return arg[:i]
}
-func runEnv(cmd *base.Command, args []string) {
+func runEnv(ctx context.Context, cmd *base.Command, args []string) {
if *envJson && *envU {
base.Fatalf("go env: cannot use -json with -u")
}
"cmd/go/internal/load"
"cmd/go/internal/modload"
"cmd/go/internal/str"
+ "context"
"fmt"
"os"
)
`,
}
-func runFix(cmd *base.Command, args []string) {
+func runFix(ctx context.Context, cmd *base.Command, args []string) {
printed := false
for _, pkg := range load.Packages(args) {
if modload.Enabled() && pkg.Module != nil && !pkg.Module.Main {
package fmtcmd
import (
+ "context"
"errors"
"fmt"
"os"
`,
}
-func runFmt(cmd *base.Command, args []string) {
+func runFmt(ctx context.Context, cmd *base.Command, args []string) {
printed := false
gofmt := gofmtPath()
procs := runtime.GOMAXPROCS(0)
import (
"bufio"
"bytes"
+ "context"
"fmt"
"go/parser"
"go/token"
CmdGenerate.Flag.StringVar(&generateRunFlag, "run", "", "")
}
-func runGenerate(cmd *base.Command, args []string) {
+func runGenerate(ctx context.Context, cmd *base.Command, args []string) {
load.IgnoreImports = true
if generateRunFlag != "" {
package get
import (
+ "context"
"fmt"
"os"
"path/filepath"
CmdGet.Flag.BoolVar(&Insecure, "insecure", Insecure, "")
}
-func runGet(cmd *base.Command, args []string) {
+func runGet(ctx context.Context, cmd *base.Command, args []string) {
if cfg.ModulesEnabled {
// Should not happen: main.go should install the separate module-enabled get code.
base.Fatalf("go get: modules not implemented")
import (
"bufio"
"bytes"
+ "context"
"encoding/json"
"io"
"os"
var nl = []byte{'\n'}
-func runList(cmd *base.Command, args []string) {
+func runList(ctx context.Context, cmd *base.Command, args []string) {
modload.LoadTests = *listTest
work.BuildInit()
out := newTrackingWriter(os.Stdout)
package modcmd
import (
+ "context"
"encoding/json"
"os"
GoModSum string `json:",omitempty"`
}
-func runDownload(cmd *base.Command, args []string) {
+func runDownload(ctx context.Context, cmd *base.Command, args []string) {
// Check whether modules are enabled and whether we're in a module.
if cfg.Getenv("GO111MODULE") == "off" {
base.Fatalf("go: modules disabled by GO111MODULE=off; see 'go help modules'")
import (
"bytes"
+ "context"
"encoding/json"
"errors"
"fmt"
base.AddBuildFlagsNX(&cmdEdit.Flag)
}
-func runEdit(cmd *base.Command, args []string) {
+func runEdit(ctx context.Context, cmd *base.Command, args []string) {
anyFlags :=
*editModule != "" ||
*editGo != "" ||
import (
"bufio"
+ "context"
"os"
"sort"
work.AddModCommonFlags(cmdGraph)
}
-func runGraph(cmd *base.Command, args []string) {
+func runGraph(ctx context.Context, cmd *base.Command, args []string) {
if len(args) > 0 {
base.Fatalf("go mod graph: graph takes no arguments")
}
"cmd/go/internal/base"
"cmd/go/internal/modload"
"cmd/go/internal/work"
+ "context"
"os"
"strings"
)
work.AddModCommonFlags(cmdInit)
}
-func runInit(cmd *base.Command, args []string) {
+func runInit(ctx context.Context, cmd *base.Command, args []string) {
modload.CmdModInit = true
if len(args) > 1 {
base.Fatalf("go mod init: too many arguments")
"cmd/go/internal/modfetch"
"cmd/go/internal/modload"
"cmd/go/internal/work"
+ "context"
"golang.org/x/mod/module"
)
work.AddModCommonFlags(cmdTidy)
}
-func runTidy(cmd *base.Command, args []string) {
+func runTidy(ctx context.Context, cmd *base.Command, args []string) {
if len(args) > 0 {
base.Fatalf("go mod tidy: no arguments allowed")
}
import (
"bytes"
+ "context"
"fmt"
"io"
"io/ioutil"
work.AddModCommonFlags(cmdVendor)
}
-func runVendor(cmd *base.Command, args []string) {
+func runVendor(ctx context.Context, cmd *base.Command, args []string) {
if len(args) != 0 {
base.Fatalf("go mod vendor: vendor takes no arguments")
}
import (
"bytes"
+ "context"
"errors"
"fmt"
"io/ioutil"
work.AddModCommonFlags(cmdVerify)
}
-func runVerify(cmd *base.Command, args []string) {
+func runVerify(ctx context.Context, cmd *base.Command, args []string) {
if len(args) != 0 {
// NOTE(rsc): Could take a module pattern.
base.Fatalf("go mod verify: verify takes no arguments")
package modcmd
import (
+ "context"
"fmt"
"strings"
work.AddModCommonFlags(cmdWhy)
}
-func runWhy(cmd *base.Command, args []string) {
+func runWhy(ctx context.Context, cmd *base.Command, args []string) {
loadALL := modload.LoadALL
if *whyVendor {
loadALL = modload.LoadVendor
package modget
import (
+ "context"
"errors"
"fmt"
"os"
m module.Version
}
-func runGet(cmd *base.Command, args []string) {
+func runGet(ctx context.Context, cmd *base.Command, args []string) {
switch getU {
case "", "upgrade", "patch":
// ok
package run
import (
+ "context"
"fmt"
"os"
"path"
return fmt.Fprint(os.Stderr, args...)
}
-func runRun(cmd *base.Command, args []string) {
+func runRun(ctx context.Context, cmd *base.Command, args []string) {
work.BuildInit()
var b work.Builder
b.Init()
import (
"bytes"
+ "context"
"crypto/sha256"
"errors"
"fmt"
// "-unusedresult",
}
-func runTest(cmd *base.Command, args []string) {
+func runTest(ctx context.Context, cmd *base.Command, args []string) {
modload.LoadTests = true
pkgArgs, testArgs = testFlags(args)
package tool
import (
+ "context"
"fmt"
"os"
"os/exec"
CmdTool.Flag.BoolVar(&toolN, "n", false, "")
}
-func runTool(cmd *base.Command, args []string) {
+func runTool(ctx context.Context, cmd *base.Command, args []string) {
if len(args) == 0 {
listTools()
return
import (
"bytes"
+ "context"
"encoding/binary"
"fmt"
"os"
versionV = CmdVersion.Flag.Bool("v", false, "")
)
-func runVersion(cmd *base.Command, args []string) {
+func runVersion(ctx context.Context, cmd *base.Command, args []string) {
if len(args) == 0 {
if *versionM || *versionV {
fmt.Fprintf(os.Stderr, "go version: flags can only be used with arguments\n")
"cmd/go/internal/load"
"cmd/go/internal/modload"
"cmd/go/internal/work"
+ "context"
"path/filepath"
)
`,
}
-func runVet(cmd *base.Command, args []string) {
+func runVet(ctx context.Context, cmd *base.Command, args []string) {
modload.LoadTests = true
vetFlags, pkgArgs := vetFlags(args)
package work
import (
+ "context"
"errors"
"fmt"
"go/build"
var runtimeVersion = runtime.Version()
-func runBuild(cmd *base.Command, args []string) {
+func runBuild(ctx context.Context, cmd *base.Command, args []string) {
BuildInit()
var b Builder
b.Init()
return "lib" + libname + ".so", nil
}
-func runInstall(cmd *base.Command, args []string) {
+func runInstall(ctx context.Context, cmd *base.Command, args []string) {
BuildInit()
InstallPackages(args, load.PackagesForBuild(args))
}
}
ctx := maybeStartTrace(context.Background())
ctx, span := trace.StartSpan(ctx, fmt.Sprint("Running ", cmd.Name(), " command"))
- _ = ctx
- cmd.Run(cmd, args)
+ cmd.Run(ctx, cmd, args)
span.Done()
base.Exit()
return