Documentation ¶
Overview ¶
Package sh includes helpers for writing programs that fork or run other programs.
Index ¶
- Constants
- func ArgsTrailer(args ...string) ([]string, error)
- func Cmd(command string, args ...string) (*exec.Cmd, error)
- func CmdContext(ctx context.Context, command string, args ...string) (*exec.Cmd, error)
- func CmdParsed(statement string) (*exec.Cmd, error)
- func CmdParsedContext(ctx context.Context, statement string) (*exec.Cmd, error)
- func Cmds(statements ...string) ([]*exec.Cmd, error)
- func Exec(command string, args ...string) error
- func ExecContext(ctx context.Context, command string, args ...string) error
- func ExecParsed(command string) error
- func ExecParsedContext(ctx context.Context, command string) error
- func Fatal(err error)
- func Fatalf(format string, args ...interface{})
- func Fork(command string, args ...string) error
- func ForkContext(ctx context.Context, command string, args ...string) error
- func ForkParsed(command string) error
- func ForkParsedContext(ctx context.Context, command string) error
- func IsEPIPE(err error) bool
- func MustCmd(command string, args ...string) *exec.Cmd
- func MustCmdParsed(statement string) *exec.Cmd
- func MustCmds(statements ...string) []*exec.Cmd
- func MustPassword(prompt string) string
- func MustToFile(path string) *os.File
- func Output(command string, args ...string) ([]byte, error)
- func OutputCmd(cmd *exec.Cmd) ([]byte, error)
- func OutputContext(ctx context.Context, command string, args ...string) ([]byte, error)
- func OutputParsed(statement string) ([]byte, error)
- func OutputParsedContext(ctx context.Context, statement string) ([]byte, error)
- func Password(prompt string) (string, error)
- func Passwordf(format string, args ...interface{}) (string, error)
- func Pipe(commands ...*exec.Cmd) error
- func Prompt(prompt string) string
- func PromptFrom(stdout io.Writer, stdin io.Reader, prompt string) string
- func Promptf(format string, args ...interface{}) string
- func Put(stdin io.Reader, command string, args ...string) error
- func PutContext(ctx context.Context, stdin io.Reader, command string, args ...string) error
- func PutOutput(stdin io.Reader, command string, args ...string) ([]byte, error)
- func ToFile(path string) (*os.File, error)
- func Touch(path string) error
- type MaxBytesWriter
Constants ¶
const (
ErrFlagsNoTrailer ex.Class = "sh; error parsing args trailer; missing '--' token, or nothing follows it"
)
Errors
const (
ErrMaxBytesWriterCapacityLimit ex.Class = "write failed; maximum capacity reached or would be exceede"
)
Errors
const ErrUnexpectedNewLine ex.Class = "unexpected newline"
ErrUnexpectedNewLine is returned from scan.go when you just hit enter with nothing in the prompt
Variables ¶
This section is empty.
Functions ¶
func ArgsTrailer ¶ added in v1.20201204.1
ArgsTrailer parses a set of os.Args, and returns everything after the `--` token. If there is no `--` token, an exception class "ErrFlagsNoTrailer" is returned.
func CmdContext ¶ added in v1.20201204.1
CmdContext returns a new command with the fully qualified path of the executable within a context.
func CmdParsedContext ¶ added in v1.20201204.1
CmdParsedContext returns a command for a full comamnd statement within a context..
func Cmds ¶ added in v1.20201204.1
Cmds returns a list of commands for a given set of statements. It is useful for running a batch of commands. It will return the first error it encounters.
func Exec ¶
Exec runs a command with a given list of arguments. It resolves the command name in your $PATH list for you. It does not show output.
func ExecContext ¶ added in v1.20201204.1
ExecContext runs a command with a given list of arguments within a context. It resolves the command name in your $PATH list for you. It does not show output.
func ExecParsed ¶ added in v1.20201204.1
ExecParsed parses a command string into binary and args. It resolves the command name in your $PATH list for you. It does not show output.
func ExecParsedContext ¶ added in v1.20201204.1
ExecParsedContext parses a command string into binary and args within a context. It resolves the command name in your $PATH list for you. It does not show output.
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf exits the process with a given formatted message to stderr.
func Fork ¶
Fork runs a command with a given list of arguments. It resolves the command name in your $PATH list for you. It shows output and allows input. It is intended to be used in scripting.
func ForkContext ¶ added in v1.20201204.1
ForkContext runs a command with a given list of arguments and context. It resolves the command name in your $PATH list for you. It shows output and allows input. It is intended to be used in scripting.
func ForkParsed ¶ added in v1.20201204.1
ForkParsed parses a command into binary and arguments. It resolves the command name in your $PATH list for you. It shows output and allows input. It is intended to be used in scripting.
func ForkParsedContext ¶ added in v1.20201204.1
ForkParsedContext parses a command into binary and arguments. It resolves the command name in your $PATH list for you. It shows output and allows input. It is intended to be used in scripting.
func MustCmd ¶
MustCmd returns a new command with the fully qualified path of the executable. It panics on error.
func MustCmdParsed ¶
MustCmdParsed returns a command for a full comamnd statement.
func MustCmds ¶
MustCmds returns a list of commands for a given set of statements. It is useful for running a batch of commands. It panics on error.
func MustPassword ¶
MustPassword gives a prompt and reads input until newlines without printing the input to screen. The prompt is written to stdout with `fmt.Print` unchanged. It panics on error.
func MustToFile ¶ added in v1.20201204.1
MustToFile opens or creates a file and panics on error. This is meant to be used as an output writer for a command.
func Output ¶
Output runs a command with a given list of arguments. It resolves the command name in your $PATH list for you. It captures combined output and returns it as bytes.
func OutputContext ¶ added in v1.20201204.1
OutputContext runs a command with a given list of arguments. It resolves the command name in your $PATH list for you. It captures combined output and returns it as bytes.
func OutputParsed ¶ added in v1.20201204.1
OutputParsed parses a command as binary and arguments. It resolves the command name in your $PATH list for you. It captures combined output and returns it as bytes.
func OutputParsedContext ¶ added in v1.20201204.1
OutputParsedContext parses a command as binary and arguments with a given context. It resolves the command name in your $PATH list for you. It captures combined output and returns it as bytes.
func Password ¶
Password prints a prompt and reads input until newlines without printing the input to screen. The prompt is written to stdout with `fmt.Print` unchanged.
func Passwordf ¶
Passwordf gives a prompt and reads input until newlines without printing the input to screen. The prompt is written to stdout with `fmt.Printf` unchanged.
func Pipe ¶
Pipe runs commands in sequence, piping combined output to the standard in of the next command.
func PromptFrom ¶
PromptFrom gives a prompt and reads input until newlines from a given set of streams.
func PutContext ¶ added in v1.20201204.1
PutContext runs a given command with a given reader as its stdin in a context.
func PutOutput ¶
PutOutput runs a given command with a given reader as its stdin and captures the output.
Types ¶
type MaxBytesWriter ¶ added in v1.20201204.1
MaxBytesWriter returns a maximum bytes writer.
func LimitBytes ¶ added in v1.20201204.1
func LimitBytes(maxBytes int, inner io.Writer) *MaxBytesWriter
LimitBytes returns a new max bytes writer.
func (*MaxBytesWriter) Count ¶ added in v1.20201204.1
func (mbw *MaxBytesWriter) Count() int
Count returns the current written bytes..
func (*MaxBytesWriter) Max ¶ added in v1.20201204.1
func (mbw *MaxBytesWriter) Max() int
Max returns the maximum bytes allowed.