base

package standard library
go1.10beta1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2017 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const ToolWindowsExtension = ".exe"

Variables

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

Configuration for finding tool binaries.

View Source
var Commands []*Command

Commands lists the available commands and help topics. The order here is the order in which they are printed by 'go help'.

View Source
var Cwd = getwd()
View Source
var Interrupted = make(chan struct{})

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

View Source
var SignalTrace os.Signal = syscall.SIGQUIT

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

View Source
var Usage func()

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

Functions

func AddBuildFlagsNX

func AddBuildFlagsNX(flags *flag.FlagSet)

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

func AtExit

func AtExit(f func())

func EnvForDir

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

EnvForDir returns a copy of the environment suitable for running in the given directory. The environment is the current process's environment but with an updated $PWD, so that an os.Getwd in the child will be faster.

func Errorf

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

func Exit

func Exit()

func ExitIfErrors

func ExitIfErrors()

func ExpandScanner

func ExpandScanner(err error) error

ExpandScanner expands a scanner.List error into all the errors in the list. The default Error method only shows the first error and does not shorten paths.

func Fatalf

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

func IsTestFile

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 MergeEnvLists

func MergeEnvLists(in, out []string) []string

MergeEnvLists merges the two environment lists such that variables with the same name in "in" replace those in "out". This always returns a newly allocated slice.

func RelPaths

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

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

func RunStdin(cmdline []string)

RunStdin is like run but connects Stdin.

func SetExitStatus

func SetExitStatus(n int)

func ShortPath

func ShortPath(path string) string

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

func StartSigHandlers

func StartSigHandlers()

StartSigHandlers starts the signal handlers.

func Tool

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.

Types

type Command

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 first word in the line is 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
}

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

func (*Command) Name

func (c *Command) Name() string

Name returns the command's name: the first word in the usage line.

func (*Command) Runnable

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

func (c *Command) Usage()

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL