Documentation ¶
Overview ¶
Package base defines shared basic pieces of the go command, in particular logging and the Command structure.
Index ¶
- Variables
- func AddBuildFlagsNX(flags *flag.FlagSet)
- func AddChdirFlag(flags *flag.FlagSet)
- func AddModCommonFlags(flags *flag.FlagSet)
- func AddModFlag(flags *flag.FlagSet)
- func AppendPATH(base []string) []string
- func AppendPWD(base []string, dir string) []string
- func AtExit(f func())
- func Cwd() string
- func Errorf(format string, args ...any)
- func Exit()
- func ExitIfErrors()
- func Fatalf(format string, args ...any)
- func GOFLAGS() []string
- func GetExitStatus() int
- func InGOFLAGS(flag string) bool
- func InitGOFLAGS()
- func IsNull(path string) bool
- func IsTestFile(file string) bool
- func RelPaths(paths []string) []string
- func Run(cmdargs ...any)
- func RunStdin(cmdline []string)
- func SetExitStatus(n int)
- func SetFromGOFLAGS(flags *flag.FlagSet)
- func ShortPath(path string) string
- func StartSigHandlers()
- func Tool(toolName string) string
- func ToolCommand(exe string, args ...string) *exec.Cmd
- type Command
- type StringsFlag
Constants ¶
This section is empty.
Variables ¶
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.
Functions ¶
func AddBuildFlagsNX ¶
AddBuildFlagsNX adds the -n and -x build flags to the flag set.
func AddChdirFlag ¶ added in v0.3.205
AddChdirFlag adds the -C flag to the flag set.
func AddModCommonFlags ¶
AddModCommonFlags adds the module-related flags common to build commands and 'go mod' subcommands.
func AddModFlag ¶
AddModFlag adds the -mod build flag to the flag set.
func AppendPATH ¶
AppendPATH returns the result of appending PATH=$GOROOT/bin:$PATH (or the platform equivalent) to the environment base.
func AppendPWD ¶
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, and also improves the accuracy of paths relative to dir if one or more elements of dir is a symlink.
func Cwd ¶
func Cwd() string
Cwd returns the current working directory at the time of the first call.
func ExitIfErrors ¶
func ExitIfErrors()
func GOFLAGS ¶
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 ¶
func GetExitStatus() int
func InitGOFLAGS ¶
func InitGOFLAGS()
InitGOFLAGS initializes the goflags list from $GOFLAGS. If goflags is already initialized, it does nothing.
func IsNull ¶ added in v0.3.205
IsNull reports whether the path is a common name for the null device. It returns true for /dev/null on Unix, or NUL (case-insensitive) on Windows.
func IsTestFile ¶
IsTestFile reports whether the source file is a set of tests and should therefore be excluded from coverage analysis.
func RelPaths ¶
RelPaths returns a copy of paths with absolute paths made relative to the current directory if they would be shorter.
func Run ¶
func Run(cmdargs ...any)
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 SetExitStatus ¶
func SetExitStatus(n int)
func SetFromGOFLAGS ¶
SetFromGOFLAGS sets the flags in the given flag set using settings in $GOFLAGS.
Types ¶
type Command ¶
type Command struct { // Run runs the command. // The args are the arguments after the command name. 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. 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 ¶
LongName returns the command's long name: all the words in the usage line between "go" and a flag or argument,
func (*Command) Name ¶
Name returns the command's short name: the last word in the usage line before a flag or argument.
type StringsFlag ¶
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 ¶
func (v *StringsFlag) Set(s string) error
func (*StringsFlag) String ¶
func (v *StringsFlag) String() string