Documentation
¶
Overview ¶
Package cliutil is common command line utils for Go.
Index ¶
- Variables
- func DefaultLoggingFunc(_ []byte)
- func ExecContext(ctx context.Context, command string, args ...string) (output string, err error)
- func ExecErrPipe(ctx context.Context, fn LoggingFunc, command string, args ...string) error
- func ExecPipe(ctx context.Context, fn LoggingFunc, command string, args ...string) error
- func IsHelpCmd(short ...string) bool
- func IsVersionCmd(short ...string) bool
- func RetrieveFlag(args []string, long, short string) (value string, ok bool)
- func RetrieveFlagFromCLI(long string, short string) (value string, ok bool)
- func ShellExec(command string) (output string, err error)
- func ShellExecContext(ctx context.Context, command string) (output string, err error)
- func ShellExecPipe(ctx context.Context, fn LoggingFunc, command string) error
- type ErrExit
- type LoggingFunc
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidCmd = errors.New("invalid command")
ErrInvalidCmd represents a invalid command error.
Functions ¶
func DefaultLoggingFunc ¶ added in v0.1.7
func DefaultLoggingFunc(_ []byte)
DefaultLoggingFunc do nothing
func ExecContext ¶
ExecContext executes the given command.
func ExecErrPipe ¶ added in v0.1.33
ExecErrPipe executes the given command with a pipe that will be connected to the command's stderr when the command starts.
func ExecPipe ¶
ExecPipe executes the given command with a pipe that will be connected to the command's stdout when the command starts.
func IsHelpCmd ¶ added in v0.1.37
IsHelpCmd this function simply calls RetrieveFlagFromCLI("--help", "") Optionally, a single extra argument of type string can be provided to indicate the short name of the help flag.
func IsVersionCmd ¶ added in v0.1.37
IsVersionCmd this function simply calls RetrieveFlagFromCLI("--version", "") Optionally, a single extra argument of type string can be provided to indicate the short name of the version flag.
func RetrieveFlag ¶ added in v0.1.14
RetrieveFlag returns value of the given flag from args.
func RetrieveFlagFromCLI ¶ added in v0.1.14
RetrieveFlagFromCLI returns value of the given flag from os.Args.
func ShellExecContext ¶
ShellExecContext executes the given command by shell.
func ShellExecPipe ¶
func ShellExecPipe(ctx context.Context, fn LoggingFunc, command string) error
ShellExecPipe executes the given command with a pipe that will be connected to the command's stdout and stderr when the command starts.
Types ¶
type ErrExit ¶
type ErrExit struct {
// contains filtered or unexported fields
}
ErrExit error with stdout and stderr.
type LoggingFunc ¶ added in v0.1.7
type LoggingFunc func(line []byte)
LoggingFunc callback function for logging command output