Go: cmd/go/internal/base Index | Files

package base

import "cmd/go/internal/base"

Package base defines shared basic pieces of the go command, in particular logging and the Command structure.


Package Files

base.go env.go flag.go goflags.go path.go signal.go signal_unix.go tool.go


const ToolWindowsExtension = ".exe"


var (
    ToolGOOS      = runtime.GOOS
    ToolGOARCH    = runtime.GOARCH
    ToolIsWindows = ToolGOOS == "windows"
    ToolDir       = build.ToolDir

Configuration for finding tool binaries.

var Cwd = getwd()
var Go = &Command{
    UsageLine: "go",
    Long:      `Go is a tool for managing Go source code.`,
var Interrupted = make(chan struct{})

Interrupted is closed when the go command receives an interrupt signal.

var SignalTrace os.Signal = syscall.SIGQUIT

SignalTrace is the signal to send to make a Go program crash with a stack trace.

var Usage func()

Usage is the usage-reporting function, filled in by package main but here for reference by other packages.

func AddBuildFlagsNX Uses

func AddBuildFlagsNX(flags *flag.FlagSet)

AddBuildFlagsNX adds the -n and -x build flags to the flag set.

func AddKnownFlag Uses

func AddKnownFlag(name string)

AddKnownFlag adds name to the list of known flags for use in $GOFLAGS.

func AddLoadFlags Uses

func AddLoadFlags(flags *flag.FlagSet)

AddLoadFlags adds the -mod build flag to the flag set.

func AppendPWD Uses

func AppendPWD(base []string, dir string) []string

AppendPWD returns the result of appending PWD=dir to the environment base.

The resulting environment makes os.Getwd more efficient for a subprocess running in dir.

func AtExit Uses

func AtExit(f func())

func Errorf Uses

func Errorf(format string, args ...interface{})

func Exit Uses

func Exit()

func ExitIfErrors Uses

func ExitIfErrors()

func Fatalf Uses

func Fatalf(format string, args ...interface{})

func GOFLAGS Uses

func GOFLAGS() []string

GOFLAGS returns the flags from $GOFLAGS. The list can be assumed to contain one string per flag, with each string either beginning with -name or --name.

func GetExitStatus Uses

func GetExitStatus() int

func InGOFLAGS Uses

func InGOFLAGS(flag string) bool

InGOFLAGS returns whether GOFLAGS contains the given flag, such as "-mod".

func InitGOFLAGS Uses

func InitGOFLAGS()

InitGOFLAGS initializes the goflags list from $GOFLAGS. If goflags is already initialized, it does nothing.

func IsTestFile Uses

func IsTestFile(file string) bool

IsTestFile reports whether the source file is a set of tests and should therefore be excluded from coverage analysis.

func RelPaths Uses

func RelPaths(paths []string) []string

RelPaths returns a copy of paths with absolute paths made relative to the current directory if they would be shorter.

func Run Uses

func Run(cmdargs ...interface{})

Run runs the command, with stdout and stderr connected to the go command's own stdout and stderr. If the command fails, Run reports the error using Errorf.

func RunStdin Uses

func RunStdin(cmdline []string)

RunStdin is like run but connects Stdin.

func SetExitStatus Uses

func SetExitStatus(n int)

func SetFromGOFLAGS Uses

func SetFromGOFLAGS(flags *flag.FlagSet)

SetFromGOFLAGS sets the flags in the given flag set using settings in $GOFLAGS.

func ShortPath Uses

func ShortPath(path string) string

ShortPath returns an absolute or relative name for path, whatever is shorter.

func StartSigHandlers Uses

func StartSigHandlers()

StartSigHandlers starts the signal handlers.

func Tool Uses

func Tool(toolName string) string

Tool returns the path to the named tool (for example, "vet"). If the tool cannot be found, Tool exits the process.

type Command Uses

type Command struct {
    // Run runs the command.
    // The args are the arguments after the command name.
    Run func(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.
    UsageLine string

    // Short is the short description shown in the 'go help' output.
    Short string

    // Long is the long message shown in the 'go help <this-command>' output.
    Long string

    // Flag is a set of flags specific to this command.
    Flag flag.FlagSet

    // CustomFlags indicates that the command will do its own
    // flag parsing.
    CustomFlags bool

    // Commands lists the available commands and help topics.
    // The order here is the order in which they are printed by 'go help'.
    // Note that subcommands are in general best avoided.
    Commands []*Command

A Command is an implementation of a go command like go build or go fix.

func (*Command) LongName Uses

func (c *Command) LongName() string

LongName returns the command's long name: all the words in the usage line between "go" and a flag or argument,

func (*Command) Name Uses

func (c *Command) Name() string

Name returns the command's short name: the last word in the usage line before a flag or argument.

func (*Command) Runnable Uses

func (c *Command) Runnable() bool

Runnable reports whether the command can be run; otherwise it is a documentation pseudo-command such as importpath.

func (*Command) Usage Uses

func (c *Command) Usage()

type StringsFlag Uses

type StringsFlag []string

A StringsFlag is a command-line flag that interprets its argument as a space-separated list of possibly-quoted strings.

func (*StringsFlag) Set Uses

func (v *StringsFlag) Set(s string) error

func (*StringsFlag) String Uses

func (v *StringsFlag) String() string

Package base imports 14 packages (graph) and is imported by 105 packages. Updated 2020-11-13. Refresh now. Tools for package owners.