Documentation ¶
Index ¶
- func MustRunCommand(cmd Command, opts ...RunCommandOption)
- func NewCommand(args []string) command
- func ProcessCommand[T Command](cmd Command, p CommandProcessor[T]) error
- func RunCommand(cmd Command, opts ...RunCommandOption) error
- type Command
- type CommandProcessor
- type CommandType
- type CompileCommand
- func (cmd *CompileCommand) AddFiles(files []string)
- func (cmd *CompileCommand) Args() []string
- func (cmd *CompileCommand) Close() error
- func (cmd *CompileCommand) GoFiles() []string
- func (cmd *CompileCommand) OnClose(cb func() error)
- func (cmd *CompileCommand) ReplaceParam(param string, val string) error
- func (c *CompileCommand) ShowVersion() bool
- func (*CompileCommand) Type() CommandType
- type LinkCommand
- func (cmd *LinkCommand) Args() []string
- func (cmd *LinkCommand) Close() error
- func (cmd *LinkCommand) OnClose(cb func() error)
- func (cmd *LinkCommand) ReplaceParam(param string, val string) error
- func (cmd *LinkCommand) ShowVersion() bool
- func (cmd *LinkCommand) Stage() string
- func (*LinkCommand) Type() CommandType
- type RunCommandOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustRunCommand ¶
func MustRunCommand(cmd Command, opts ...RunCommandOption)
MustRunCommand is like RunCommand but panics if the command fails to build or run
func NewCommand ¶
func NewCommand(args []string) command
NewCommand initializes a new command object and takes care of tracking the indexes of its arguments
func ProcessCommand ¶
func ProcessCommand[T Command](cmd Command, p CommandProcessor[T]) error
ProcessCommand applies a processor on a command if said command matches the input type of said input processor. Nothing happens if the processor does not correspond to the provided command type.
func RunCommand ¶
func RunCommand(cmd Command, opts ...RunCommandOption) error
RunCommand executes the underlying go tool command and forwards the program's standard fluxes
Types ¶
type Command ¶
type Command interface { // Close invokes all registered OnClose callbacks and releases any resources associated with the // command. Close() error // Args are all the command arguments, starting from the Go tool command Args() []string ReplaceParam(param string, val string) error // Type represents the go tool command type (compile, link, asm, etc.) Type() CommandType // ShowVersion returns true if the command received the `-V=full` argument, signaling it should // print its full version information and exit. This feature is used by the go toolchain to // create build cache keys, and allows invalidating all build cache when the tooling changes. ShowVersion() bool }
Command represents a Go compilation command
func MustParseCommand ¶
MustParseCommand calls ParseCommand and exits on error
func ParseCommand ¶
ParseCommand parses the Go tool call and its arguments and returns it as a Command. The go tool call path should be the first element of args
type CommandProcessor ¶
CommandProcessor is a function that takes a command as input and is allowed to modify it or read its data. If it returns an error, the processing chain immediately stops and no further processors will be invoked.
type CommandType ¶
type CommandType int
CommandType represents a Go toolchain command type, such as "compile", "link", etc...
const ( CommandTypeOther CommandType = iota CommandTypeCompile CommandTypeLink )
type CompileCommand ¶
type CompileCommand struct { Flags compileFlagSet Files []string // WorkDir is the $WORK directory managed by the go toolchain. WorkDir string // contains filtered or unexported fields }
CompileCommand represents a go tool `compile` invocation
func (*CompileCommand) AddFiles ¶
func (cmd *CompileCommand) AddFiles(files []string)
AddFiles adds the provided go files paths to the list of Go files passed as arguments to cmd
func (*CompileCommand) GoFiles ¶
func (cmd *CompileCommand) GoFiles() []string
GoFiles returns the list of Go files passed as arguments to cmd
func (*CompileCommand) OnClose ¶
func (cmd *CompileCommand) OnClose(cb func() error)
OnClose registers a callback to be invoked when the command is closed, usually after it has run, unless skipping was requested by the integration.
func (*CompileCommand) ReplaceParam ¶
ReplaceParam will replace any parameter of the command provided it is found A parameter can be a flag, an option, a value, etc
func (*CompileCommand) ShowVersion ¶
func (c *CompileCommand) ShowVersion() bool
func (*CompileCommand) Type ¶
func (*CompileCommand) Type() CommandType
type LinkCommand ¶
type LinkCommand struct { Flags linkFlagSet // WorkDir is the $WORK directory managed by the go toolchain. WorkDir string // contains filtered or unexported fields }
LinkCommand represents a go tool `link` invocation
func (*LinkCommand) OnClose ¶
func (cmd *LinkCommand) OnClose(cb func() error)
OnClose registers a callback to be invoked when the command is closed, usually after it has run, unless skipping was requested by the integration.
func (*LinkCommand) ReplaceParam ¶
ReplaceParam will replace any parameter of the command provided it is found A parameter can be a flag, an option, a value, etc
func (*LinkCommand) ShowVersion ¶
func (cmd *LinkCommand) ShowVersion() bool
func (*LinkCommand) Stage ¶
func (cmd *LinkCommand) Stage() string
func (*LinkCommand) Type ¶
func (*LinkCommand) Type() CommandType
type RunCommandOption ¶
RunCommandOption allows customizing a run command before execution. For example, this can be used to capture the output of the command instead of forwarding it to the host process' STDIO.