Documentation
¶
Index ¶
- func If(logic string, dir string, env []string) bool
- func InputSelect(msg string, opts ...string) int
- func InputText(msg string) string
- func InputYN(msg string, def ...bool) bool
- func Pipe(dir string, args ...[]string)
- func PipeMultiDir(args ...[]string)
- func PipeMultiDirEnv(env []string, args ...[]string)
- func Run(args []string, dir string, env []string, liveOutput ...bool) (output []byte, err error)
- func RunRaw(cmdStr string, dir string, env []string, liveOutput ...bool) (output []byte, err error)
- func RunUser(cmdStr string, user string, dir string, env []string, liveOutput ...bool) (output []byte, err error)
- func RunUserFile(file string, args []string, user string, dir string, env []string, ...) (output []byte, err error)
- type ProgressBar
- type SystemSleepLock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func If ¶ added in v0.1.3
If will run a bash if [[ logic ]] method, and return true or false to the output for go to process
note: uses RunRaw method
func InputSelect ¶
InputSelect prompts the user to select from a list of options and returns the selected index
func Pipe ¶
Pipe allows you to pipe multiple bash commands
[example (bash)]
echo "test" | tee -a "./test.txt"
[example (go)]
bash.Pipe(".", []string{"echo", "test"}, []string{"tee", "-a", "./test.txt"})
@dir: a directory to run the command in (set to an empty string to disable)
func PipeMultiDir ¶
func PipeMultiDir(args ...[]string)
PipeMultiDir allows you to pipe multiple bash commands with a different directory for each of them
note: the first arg is the directory
[example]
bash.PipeMultiDir([]string{"/dir1", "cat", "test.txt"}, []string{"./dir2", "tee", "-a", "./test.txt"})
func PipeMultiDirEnv ¶
PipeMultiDirEnv is just like the 'PipeMultiDir' method, but it also allows you to add custom envirronment vars
note: the first arg is the directory
[example]
bash.PipeMultiDirEnv([]string{`MyEnvVar=CustomValue`}, []string{"/dir1", "cat", "test.txt"}, []string{"./dir2", "tee", "-a", "./test.txt"})
func Run ¶
Run will run a bash command based on the given args
note: stdin is piped to the os logs
@dir: a directory to run the command in (set to an empty string to disable) @env: an optional list of environment variables (set to nil to disable)
[optional]
@liveOutput[0]: set to true to pipe stdout and stderr to the os @liveOutput[1]: set to false to only pipe stdout to the os, and keep stderr hidden
func RunRaw ¶
RunRaw will run an unescaped (unquoted) bash command as a different user
this method uses `bash -c` to get around the auto quotes added by golang
note: user input is Not recommended for this method
note: stdin is piped to the os logs
@cmdStr: the command to run @dir: a directory to run the command in (set to an empty string to disable) @env: an optional list of environment variables (set to nil to disable)
[optional]
@liveOutput[0]: set to true to pipe stdout and stderr to the os @liveOutput[1]: set to false to only pipe stdout to the os, and keep stderr hidden
func RunUser ¶
func RunUser(cmdStr string, user string, dir string, env []string, liveOutput ...bool) (output []byte, err error)
RunUser will run an unescaped (unquoted) bash command as a specified user
this method uses `runuser -l [user] -c`
note: user input is Not recommended for this method
note: stdin is piped to the os logs
@cmdStr: the command to run @user: the username to run the command as @dir: a directory to run the command in (set to an empty string to disable) @env: an optional list of environment variables (set to nil to disable)
[optional]
@liveOutput[0]: set to true to pipe stdout and stderr to the os @liveOutput[1]: set to false to only pipe stdout to the os, and keep stderr hidden
func RunUserFile ¶
func RunUserFile(file string, args []string, user string, dir string, env []string, liveOutput ...bool) (output []byte, err error)
RunUserFile will run a bash file as a specified user
this method uses `pkexec --user [user]` to simulate a user in a normal desktop environment
note: user input is Not recommended for this method
note: stdin is piped to the os logs
@file: the file to run @user: the username to run the command as @dir: a directory to run the command in (set to an empty string to disable) @env: an optional list of environment variables (set to nil to disable)
[optional]
@liveOutput[0]: set to true to pipe stdout and stderr to the os @liveOutput[1]: set to false to only pipe stdout to the os, and keep stderr hidden
Types ¶
type ProgressBar ¶
type ProgressBar struct {
// contains filtered or unexported fields
}
func NewProgressBar ¶
func NewProgressBar(msg string) *ProgressBar
NewProgressBar creates a new terminal progress bar
func (*ProgressBar) AddSize ¶ added in v0.1.2
func (pb *ProgressBar) AddSize(size int)
AddSize adds to the total size of the progress bar for the Step method
func (*ProgressBar) Msg ¶
func (pb *ProgressBar) Msg(msg string)
Msg changes the message for the progress bar
func (*ProgressBar) SetLevel ¶
func (pb *ProgressBar) SetLevel(level float64)
SetLevel sets the current percentage level of the progress bar
func (*ProgressBar) SetSize ¶
func (pb *ProgressBar) SetSize(size int)
SetSize sets the total size of the progress bar for the Step method
func (*ProgressBar) Step ¶
func (pb *ProgressBar) Step(size ...int)
Step increments the progress bar by size (default 1)
func (*ProgressBar) Stop ¶
func (pb *ProgressBar) Stop()
Stop stops the progress bar and cleans up the terminal
type SystemSleepLock ¶ added in v0.1.5
type SystemSleepLock struct {
// contains filtered or unexported fields
}
func SleepLock ¶ added in v0.1.5
func SleepLock() *SystemSleepLock
SleepLock prevents the system from sleeping by using systemd-inhibit
func (*SystemSleepLock) Release ¶ added in v0.1.5
func (lock *SystemSleepLock) Release()
Release releases the sleep lock