amalgomated

package
v1.40.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 7 Imported by: 70

Documentation

Index

Constants

View Source
const ProxyCmdPrefix = "__"

Variables

This section is empty.

Functions

func RunApp

func RunApp(osArgs []string, fset *flag.FlagSet, cmdLibrary CmdLibrary, app func(osArgs []string) int) int

RunApp runs an application using the provided arguments. The arguments should be of the same form as os.Args (the first element contains the invoking executable command and the rest contain the elements). If there are flags that can occur before the proxy command that should be ignored for the purposes of determining whether or not a command is a proxy command, they should be provided in "fset". If osArgs[1] of the non-flag arguments exists and is a proxy command, the corresponding command in cmdSet is run with the rest of the arguments and os.Exit is called. Otherwise, the provided "app" function is run and its return value is returned.

Types

type Cmd

type Cmd interface {
	Name() string
}

Cmd represents a command that should be run. It is used as a key provided to a CmderSupplier to generate a Cmder.

type CmdLibrary

type CmdLibrary interface {
	// Run runs the provided command.
	Run(cmd Cmd)
	// Cmds returns the set of valid commands.
	Cmds() []Cmd
	// NewCmd creates a new Cmd for this library using the provided string. Returns an error if the provided string
	// does not correspond to a valid command for this library.
	NewCmd(cmd string) (Cmd, error)
	// MustNewCmd performs the same operation as NewCmd, but panics if NewCmd returns a non-nil error.
	MustNewCmd(cmd string) Cmd
}

CmdLibrary represents a library of commands that can be run.

func NewCmdLibrary

func NewCmdLibrary(cmdSet StringCmdSet) CmdLibrary

type CmdWithRunner

type CmdWithRunner struct {
	// contains filtered or unexported fields
}

CmdWithRunner pairs a named command with the function for the command.

func MustNewCmdWithRunner

func MustNewCmdWithRunner(cmdName string, runner func()) *CmdWithRunner

MustNewCmdWithRunner returns the result of NewCmdWithRunner and panics in cases where the function returns an error.

func NewCmdWithRunner

func NewCmdWithRunner(cmdName string, runner func()) (*CmdWithRunner, error)

NewCmdWithRunner creates a new CmdWithRunner for the provided name and runner. Returns an error if the provided name is not a legal command name.

func (*CmdWithRunner) Name

func (c *CmdWithRunner) Name() string

type Cmder

type Cmder interface {
	// Cmd returns the *exec.Cmd object configured with the provided arguments and with possible
	// implementation-specific augmentations. The returned command has not yet been executed or run, and the caller
	// may change the configuration as desired before executing the command. The returned command is ready to call,
	// and a standard use case is to call CombinedOutput() on the returned command to execute it and retrieve the
	// output generated to stdOut and stdErr.
	Cmd(args []string, cmdWd string) *exec.Cmd
}

Cmder creates an *exec.Cmd that can be run.

func CmderWithPrependedArgs

func CmderWithPrependedArgs(r Cmder, prependedArgs ...string) Cmder

CmderWithPrependedArgs returns a new Cmder that invokes the provided Cmder, but always adds the provided "prependedArgs" before any user-supplied arguments. Note that if the runner being wrapped has a notion of "prependedArgs" itself, those arguments will precede the "prependedArgs" provided in this method.

func PathCmder

func PathCmder(pathToExecutable string, prependedArgs ...string) Cmder

PathCmder returns a Cmder that runs the command at the supplied path with the specified "prependedArgs" provided as arguments to the executable before all of the other arguments that are added. The path should resolve to the executable that should be run: for example, "/usr/bin/git". The "prependedArgs" will be combined with the arguments provided to the Run method for any given execution.

type CmderSupplier

type CmderSupplier func(cmd Cmd) (Cmder, error)

CmderSupplier returns the Cmder that runs the specified command. Returns an error if a Runner cannot be created for the requested Cmd.

func SelfProxyCmderSupplier

func SelfProxyCmderSupplier() CmderSupplier

SelfProxyCmderSupplier returns a supplier that, given a command, re-invokes the current executable with a proxy version of the provided command.

func SupplierWithPrependedArgs

func SupplierWithPrependedArgs(s CmderSupplier, argsFunc func(cmd Cmd) []string) CmderSupplier

SupplierWithPrependedArgs returns a new Supplier that invokes the provided supplier and returns the result of calling RunnerWithPrependedArgs on the returned runner with the result of applying the provided "argsFunc" function to the provided command.

type StringCmdSet

type StringCmdSet interface {
	Run(cmd string)
	Cmds() []string
}

StringCmdSet is a set of commands that can be run that are represented as strings.

func NewStringCmdSetForRunners

func NewStringCmdSetForRunners(cmds ...*CmdWithRunner) (StringCmdSet, error)

NewStringCmdSetForRunners creates a new StringCmdSet from the provided cmds (all of which must be non-nil). Returns an error if any of the provided commands have the same name.

Jump to

Keyboard shortcuts

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