Documentation ¶
Index ¶
- Variables
- func AppArgs(usage string, in ...string) (appMessage string, args []string, err error)
- func CheckPnameRunning(pname string) bool
- func Command(args string) (out string, errno int, err error)
- func CommandContainsAll(args string, subs ...string) bool
- func CommandFormat(format string, vals ...interface{}) (string, int, error)
- func CommandScript(script []byte) (string, int, error)
- func CommandWithChan(cmd string, queue chan string) error
- func CommandWithOutErr(cmd string) (string, string, int, error)
- func Echo(args ...string) (out string, err error)
- func ErrControl() error
- func Example()
- func Exists(path string) bool
- func GetOutput(args ...string) (out string, err error)
- func GitAddAll() error
- func GitCommit(message string) error
- func GitCommitAll(message string) error
- func GitCurrentBranch() (out string, err error)
- func GitFetch() error
- func GitPush() error
- func GitPushSetUpstreamOrigin() error
- func Gitit(message string) error
- func Home() string
- func IsDir(path string) bool
- func LookPath(cmd string) bool
- func Message(msg string) string
- func NewErrorControl() *errorControl
- func NewShellError(errno *int, err error, msg *string, command *string) *shellError
- func NormalizeWhitespace(s string, saveNewLines bool) string
- func ToFields(in ...string) []string
- func WithExecMode(b bool) optionFunc
- func WithSetDir(dir string) optionFunc
- func WithSetEnv(env []string) optionFunc
- func WithShellMode() optionFunc
- func WithTimeout(td int) optionFunc
- type Cmd
- type OutputBuffer
- type OutputStream
- type Sheller
- type Status
Constants ¶
This section is empty.
Variables ¶
var ( ErrLineBufferOverflow = errors.New("line buffer overflow") ErrAlreadyFinished = errors.New("already finished") ErrNotFoundCommand = errors.New("command not found") ErrNotExecutePermission = errors.New("not execute permission") ErrInvalidArgs = errors.New("Invalid argument to exit") ErrProcessTimeout = errors.New("throw process timeout") ErrProcessCancel = errors.New("active cancel process") DefaultExitCode = 2 )
var ( TES = "" NL = "\n" TAB = "\t" )
var ( GoBot = goBot{ DefaultGitCommitMessage: "", GobotDevAutosaveMessage: defaultDevAutosaveMessage, GobotAutoSaveTimer: defaultAutoSaveInterval, // contains filtered or unexported fields } GoBotCliWriter = cliWriter{ Writer: nil, Verbose: true, Out: os.Stdout, Debug: true, Err: os.Stderr, } )
var (
Err = log.Err
)
Functions ¶
func AppArgs ¶
AppArgs parses the input arguments into a set of app, args strings variables designed for use with exec.Command.
Arguments are split on any unicode whitespace and the first arg is returned as the 'app' while the remaining are returned as a slice of strings.
Any error is also returned as a standard error.
As a courtesy, if a usage string is provided, it will be used instead of the default empty string 'app' when no arguments are provided.
func CheckPnameRunning ¶
CheckPnameRunning checks to see if a program is running.
func Command ¶
Command executes a command and returns CombinedOutput, exitcode, and err. If Stderr contains a message, the Go error is wrapped in a Stderr message.
func CommandContainsAll ¶
CommandContainsAll executes a command then searches for matches to any substrings in the output string. If ANY of the substrings are not found, the command returns false.
func CommandFormat ¶
Command executes a formatted command and returns CombinedOutput, exitcode, and err
func CommandScript ¶
CommandScript writes a script to a temp file and executes that script.
func CommandWithChan ¶
CommandWithChan executes the command and returns results in a channel
func CommandWithOutErr ¶
CommandWithOutErr runs command and return separate output: string(stdout), string(stderr), exitcode, err
func Echo ¶
Echo processes the shell command and and returns the result and any error encountered. In addition, it prints the result to stdout and any error message to stderr.
Any shell error values (errno of type int) are wrapped into the Go error message.
The io.Writers for stdout and stderr can be redirected in the configuration and all stdout and stderr output can be enabled or disabled by using the config settings Verbose and Debug, respectively.
func ErrControl ¶
func ErrControl() error
func GetOutput ¶
GetOutput returns the contents of the Stdout. Any error is returned wrapped with a Stderr message and any errno returned from the shell.
func GitCommitAll ¶
GitCommitAll processes the following commands in sequence:
git add -all git commit -m "message" (or default) git push origin main
func GitCurrentBranch ¶
func GitPushSetUpstreamOrigin ¶
func GitPushSetUpstreamOrigin() error
func Gitit ¶
Gitit is a quick and dirty git repo autosave and push.
Gitit runs the following commands in order:
go mod tidy go doc >|go.doc git add --all git commit -m $message git push
func NewErrorControl ¶
func NewErrorControl() *errorControl
func NewShellError ¶
func NormalizeWhitespace ¶
NormalizeWhitespace removes any unicode whitespace characters from s and returns a string with all words separate by single spaces (0x20). As a convenience, there is an option to ignore newlines (0xA) and leave them intact.
Whitespace is a space character as defined by Unicode's White Space property; in the Latin-1 space this is
'\t', '\n', '\v', '\f', '\r', ' ', U+0085 (NEL), U+00A0 (NBSP)
Other definitions of spacing characters are set by category Z and property Pattern_White_Space.
func ToFields ¶
ToFields converts any number of string arguments into a slice of fields, as defined by
strings.Fields()
from the standard library, and returns a slice of substrings of s or an empty slice if s contains only white space.
func WithExecMode ¶
func WithExecMode(b bool) optionFunc
WithExecMode set exec mode, example:
["curl", "-i", "-v", "xiaorui.cc"]
Types ¶
type Cmd ¶
type Cmd struct { sync.Mutex Bash string ShellMode bool Status Status Env []string Dir string // contains filtered or unexported fields }
func NewCommand ¶
type OutputBuffer ¶
func NewOutputBuffer ¶
func NewOutputBuffer() *OutputBuffer
func (*OutputBuffer) Lines ¶
func (rw *OutputBuffer) Lines() []string
type OutputStream ¶
type OutputStream struct {
// contains filtered or unexported fields
}
func NewOutputStream ¶
func NewOutputStream(streamChan chan string) *OutputStream
NewOutputStream creates a new streaming output on the given channel.
func (*OutputStream) Lines ¶
func (rw *OutputStream) Lines() <-chan string
func (*OutputStream) SetLineBufferSize ¶
func (rw *OutputStream) SetLineBufferSize(n int)