base

package
v0.24.8 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package base defines shared basic pieces of the go command, in particular logging and the Command structure. see also: https://pkg.go.dev/cmd/go/internal/base

Copyright (C) 2022 - Simon Travis. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

View Source
var ErrUsage = errors.New("error: ")

ex. fmt.Errorf("%w expected at least one word to transform", base.ErrUsage)

View Source
var Exe string = "tap"
View Source
var Go = &Command{
	UsageLine: Exe,
	Long:      `The 'tap' tool manages Tapestry stories.`,
}
View Source
var Interrupted = make(chan struct{})

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

View Source
var SignalTrace os.Signal = unix.SIGQUIT

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

Functions

func Errorf

func Errorf(format string, args ...any)

func Exit

func Exit()

func ExitWithStatus

func ExitWithStatus(status int)

func Fatalf

func Fatalf(format string, args ...any)

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 RunStdin

func RunStdin(cmdline []string)

RunStdin is like run but connects Stdin.

func SetExitStatus

func SetExitStatus(n int)

larger exit status wins; zero is the default.

func StartSigHandlers

func StartSigHandlers()

StartSigHandlers starts the signal handlers.

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) error

	// 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.
	// ex. "go fix [-fix list] [packages]"
	UsageLine string

	// Short is the short description shown in the 'go help' output.
	// ex. "update packages to use new APIs"
	Short string

	// Long is the long message shown in the 'go help <this-command>' output.
	// ex. "Fix runs the Go fix command on the packages named by the import paths...."
	// -- see help.go which contains a template used to print the command
	Long string

	// Flag is a set of flags specific to this command.
	// unless CustomFlags is specified by the command:
	// main.invoke() merges global flags and calls calls .Parse automatically
	// any remaining args are sent to Run()
	// individual commands set their own flags using init() or local vars.
	// ex. 	go get: var getD = CmdGet.Flag.Bool("d", false, "")
	Flag flag.FlagSet

	// CustomFlags indicates that the command will do its own
	// flag parsing. see: Flag.
	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) FlagUsage

func (c *Command) FlagUsage() string

func (*Command) LongName

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

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

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()

Jump to

Keyboard shortcuts

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