Documentation ¶
Overview ¶
Package util is a general utility package for REPLbot
Index ¶
- func CheckTmuxVersion() error
- func FileExists(filenames ...string) bool
- func FormatMarkdownCode(s string) string
- func InStringList(haystack []string, needle string) bool
- func Quote(s string) string
- func QuoteCommand(args []string) string
- func RandomPort() (int, error)
- func RandomString(length int) string
- func Run(command ...string) error
- func RunAll(commands ...[]string) error
- func SanitizeNonAlphanumeric(s string) string
- func StringContainsWait(haystackFn func() string, needle string, maxWait time.Duration) (contains bool)
- func StripUnsafe(s string) string
- func TempFileName() string
- func WaitUntil(fn func() bool, maxWait time.Duration) bool
- func WaitUntilNot(fn func() bool, maxWait time.Duration) bool
- type SSHKeyPair
- type Tmux
- func (s *Tmux) Active() bool
- func (s *Tmux) Capture() (string, error)
- func (s *Tmux) Cursor() (show bool, x int, y int, err error)
- func (s *Tmux) MainID() string
- func (s *Tmux) Paste(input string) error
- func (s *Tmux) RecordingFile() string
- func (s *Tmux) Resize(width, height int) error
- func (s *Tmux) SendKeys(keys ...string) error
- func (s *Tmux) Start(env map[string]string, command ...string) error
- func (s *Tmux) Stop() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckTmuxVersion ¶
func CheckTmuxVersion() error
CheckTmuxVersion checks the version of tmux and returns an error if it's not supported
func FileExists ¶
FileExists returns true if a file with the given filename exists
func FormatMarkdownCode ¶
FormatMarkdownCode formats the given string as a markdown code block
func InStringList ¶
InStringList returns true if needle is contained in the list of strings
func Quote ¶
Quote returns a shell-escaped version of the string s. The returned value is a string that can safely be used as one token in a shell command line.
func QuoteCommand ¶
QuoteCommand returns a shell-escaped version of the slice of strings. The returned value is a string that can safely be used as shell command arguments.
func RandomPort ¶
RandomPort finds a free random, operating system chosen port
func RandomString ¶
RandomString returns a random alphanumeric string of the given length
func SanitizeNonAlphanumeric ¶
SanitizeNonAlphanumeric replaces all non-alphanumeric characters with an underscore
func StringContainsWait ¶
func StringContainsWait(haystackFn func() string, needle string, maxWait time.Duration) (contains bool)
StringContainsWait is a helper function for tests to check if a string is contained within a haystack within a reasonable amount of time
func StripUnsafe ¶
StripUnsafe remove non-printable runes, e.g. control characters in a string that is meant for consumption by terminals that support control characters.
func TempFileName ¶
func TempFileName() string
TempFileName generates a random file name for a file in the temp folder
Types ¶
type SSHKeyPair ¶
SSHKeyPair represents an SSH key pair
func GenerateSSHKeyPair ¶
func GenerateSSHKeyPair() (pair *SSHKeyPair, err error)
GenerateSSHKeyPair generates an SSH key pair
type Tmux ¶
type Tmux struct {
// contains filtered or unexported fields
}
Tmux represents a very special tmux(1) setup, specifially used for dockerbot. It consists of two tmux sessions:
- session "dockerbot_$id_frame": session with one window and three panes to allow us to resize the terminal of the main pane (.2). The main pane is .2, so that if it exits there is no other pane to take its place, which is easily detectable by the other panes. The main pane (.2) connects to the main session (see below).
- session "dockerbot_$id_main": main session running the actual container.
func (*Tmux) RecordingFile ¶
RecordingFile returns the file name of the recording file. This method can only be called after the session has exited. Before that, the file will not exist.
func (*Tmux) SendKeys ¶
SendKeys invokes the tmux send-keys command, which is useful for sending control sequences